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.

Newcomers AppGameKit Corner / Detection of Sprite Collision

Author
Message
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Feb 2015 01:36
I just bought AppGameKit today and have been toying around with it. Im trying to make a simple run and jump demo. GetSpriteCollision is not returning anything for me.


Player

Object to jump over

Floor


I tried using

But GetSpriteCollision seems to return no value.

Any help would be nice. Iv been reading around and looking at examples and cant seem to get a grip on it. Thanks in advance.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Feb 2015 13:39
Your Object Loop is using the same sprite handle each time 'o'... This means when checking for a collision using the 'o' you are only checking for a collision against the very last sprite created...

I'd recommend creating an array for each of the Objects. Try this;



This will create 200 Sprites each with individual id's which you can reference back to.

Now change your collision routine to:



Hope that helps...

Using AppGameKit V2 Tier 1
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Feb 2015 14:58
Thankyou Funnell7 that did the trick...But for now only collision detection is on top of the the boxes (Things to jump) When I land on the boxes it returns value but if I just bump them from the side no value is returned. Should I just look into Raycasting?
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Feb 2015 15:12
Quote: "When I land on the boxes it returns value but if I just bump them from the side no value is returned"


You should get a value returned from GetSpriteCollision() irrespective of which side you collide with... Its hard to tell what exactly you are trying to do, but if the blocks are simply there to detect collision, I would change them to sensors;



This will allow your player to pass through them, which will guarantee you get a collision.

Using AppGameKit V2 Tier 1
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Feb 2015 16:20
No Collision detected from side


Collision is detected from top


I don't see why it wouldn't be detecting from sides
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Feb 2015 16:29
Try adding SetSpriteShape(2, 2) to your player... Does that make a difference?

Using AppGameKit V2 Tier 1
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Feb 2015 16:38 Edited at: 11th Feb 2015 17:27
No it does not, but after this last run. I have noticed my sprite does not have a set angle so with the physics it just flops across the the ground if its not jumping. If I can get it to roll into the side of a block at a certain angle it will detect collision for a split second then its not detecting it any more.

Heres all the code.



Edit: I have fixed it. Thanks for your help
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Feb 2015 19:25
You're welcome... For the benefit of any one else experiencing this, why not post the solution you found...

Using AppGameKit V2 Tier 1
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Feb 2015 20:37 Edited at: 11th Feb 2015 20:41
Here is my working solution for jumping and moving my sprite. Instead of having SetSpritePhysicsVelocity ( 2, 500, 0 ) running in my game loop to move my sprite. Instead I removed the velocity and just update my sprites x position if Jump = 0 which you can see in the code.


Working

Not Working

I don't know why
SetSpritePhysicsVelocity ( 2, 500, 0 ) running in game loop would mess with the collision detection from the side of my box sprites when the top side would be detected. If someone could jump in and explain would be a help. Also if your updating the X or Y position rapidly I can either fall through or push through my sprites with physics on.

Login to post a reply

Server time is: 2024-03-28 21:45:53
Your offset time is: 2024-03-28 21:45:53