Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Collision is not 100 percent at all times, at least I think.

Author
Message
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 07:27
So my bullets delete at collision, about 90 percent of the time, I guess it is just me or my code.

Here is my collision and delete code, I need help on this one.

The author of this post has marked a post as an answer.

Go to answer

ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 8th Nov 2021 07:51 Edited at: 8th Nov 2021 07:54
I'm not sure what the problem is but I can see where there should be a change..


BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 07:56
Hi ando

No I just added that for testing to see what would happen because not every bullet get deleted so if not I try to hide them if there not deleted.

It still does nothing.

I ask for help because there is a collision, the bullet bounce's off the target point but does not delete.

about 90 percent of the time it does.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 8th Nov 2021 08:14
I usually do little tests to track down the problem something like this..


hit=GetPhysicsCollision(shot[Bull].ID,All_Enemy[x].enemyID)
Print(" hit = "+str(hit))

just to see if the collision is actually working or is it something else.

Sorry I'm not much help
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 08:18 Edited at: 8th Nov 2021 08:19
Quote: "Sorry I'm not much help"


Your here helping, at least some people care enough to say something lol.

I'm kidding.

No, The collision makes the bullet bounce so there is collision to every bullet should all should delete, so it has to be my code some how.

I am making each bullet into a array so maybe this is why, maybe if I clone each bullet?
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 8th Nov 2021 08:33
Maybe it's a timing thing.

looks like you are deleting the bullet if end of lifetime then checking collision.

What if you move this code down lower...


BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 08:44
Quote: "What if you move this code down lower"


I tried this and nothing, that was another test thing to try to get rid of the lost bullets.

I wonder if you only get a real collision if a sprite hits the other sprites box point.

I have my sprites in boxes and only 4 points for collision.

I duck and shoot and they hit every time, but when I stand it hits most the time but not every time.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 8th Nov 2021 08:52
This post has been marked by the post author as the answer.
Maybe you are right.

I don't usually use collision for things like that.
I usually check distance between bullet and target and if it is very close then call it a hit.
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 09:04 Edited at: 8th Nov 2021 09:27
Quote: "I usually check distance between bullet and target and if it is very close then call it a hit."


Well, you just helped me, I will do this and it is brilliant.

Thanks

Edit::::

This worked, I guess collisions are not 100 percent always.

Thank you.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 8th Nov 2021 09:26 Edited at: 8th Nov 2021 09:29
Cool, I hope it works for you.

Just one little thing to watch out for.
If you are moving a bullet at speed 5 and the target is 2.5 away and you are checking if the bullet is 2 or closer then it will not count as a hit.
You probably already know that stuff.

EDIT... NICE!
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 8th Nov 2021 09:31
Yes it worked, thank you,

I had to get every bullet number to make it work but it works every time now.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 8th Nov 2021 14:01
You are checking your bullets from 0 to the length of the array.
If you are deleting a bullet then you will not check the next bullet in the array because your loop will step past the next element
you should check bullets from the length of the array to 0
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 9th Nov 2021 03:32
Quote: " you will not check the next bullet in the array because your loop will step past the next element"


I figured this also, this is why I am, using another value to get the bullet number and then it worked so I believe you are correct, as soon as I used

Bullet_Num=Shots.ID

This took it out of the array and then worked every time.

From now on I'm going to have to remember if I resize my arrays to get the value first.

Thanks blink0k

But also Using a distance I noticed there is no bullet misses now also, so every bullet is used.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 9th Nov 2021 15:16
Quote: "But also Using a distance I noticed there is no bullet misses now also, so every bullet is used."


Some times collisions can fail to register if the sprite is moving faster then the physics is updating, I stumbled across this problem years ago in GameMaker, I think I ditched the bullet collision and cast a 2d ray instead ..

Quote: "From now on I'm going to have to remember if I resize my arrays to get the value first."


If you resize an array in a loop you always, without exception, run the loop in reverse, from the top down, from end to start, iE: backwards!

For index=myArray.length to 0 Step -1
// do some stuff
myArray.remove(index) << safe to remove from the top
Next




Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 9th Nov 2021 15:35
Quote: "For index=myArray.length to 0 Step -1"


I do this and most the time I get a error of out of bounds a lot and also I did this for my bullets and it still did not work, I still had to get the number this way to remove it from the array because I am resetting the array back to 0 every bullet shoot.

But yes, I understand what you are saying.

Login to post a reply

Server time is: 2024-11-21 13:36:27
Your offset time is: 2024-11-21 13:36:27