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 / Please help with collision detection

Author
Message
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 05:52 Edited at: 11th Jul 2016 06:02
I'm having such a hard time trying to get this collision to work. Would be nice if it was physics based.

DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 05:53
This is one sprite

Attachments

Login to view attachments
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 05:54
Here is the button

Attachments

Login to view attachments
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 05:54
Here is the level

Attachments

Login to view attachments
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 11th Jul 2016 13:23
Alright let's see if i can help...
So first I'd recommend you try and use physics commands if you can, I know there are a few good reasons not to though.
If you're determined too use a custom physics system then you might want to look into raycasting commands. I've never used them myself but I'm sure you can get plenty of help on the forum if you want to try them
Now if you want to keep away from all of that, then I have a couple of ideas that you should try.
So the basic idea of doing a physics system is to do this:
1. Move the player (dynamic) sprite
2. Check for collision with any other sprites
3. Find out where the player sprite should have been when it collided
4. Set the new player position and calculate the new speed/direction of the sprite.

The hardest part is of course step three. Physics systems use lots of complicated maths, I assume you'd prefer a simpler system so I have one here for you.
Basically just this:
Store the current players motion vector (ie X speed + Y speed).
Add that to the current player position.
Check for collision.
If collision
For k = 1 to 10
|Player position=player position - player vector/10
|Check for collision again, if no collision then exit loop
Next K
Endif


Does that make sense? Basically you need a loop inside your main loop that will iterate backwards through every position the player sprite should have been between this frame and the previous frame, and finds exactly where it was when it collided.

Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
130,000 installs with AppGameKit and counting
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 18:09
Thank you for the advice, how would I do it with my current system though?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Jul 2016 19:17 Edited at: 11th Jul 2016 19:22
i made a physic example with your code.
if you will have a bounce at the window borders you need also physic sprites.
you can disable the rotate by SetSpritePhysicsCanRotate ( iSpriteIndex, rotate )
see also GetSpriteHitTest ( iSpriteIndex, x, y ) for your input screen buttons.

AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 11th Jul 2016 19:35
Thank you!

Login to post a reply

Server time is: 2024-09-29 15:14:56
Your offset time is: 2024-09-29 15:14:56