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 / Question about collisions

Author
Message
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 2nd Feb 2016 09:31 Edited at: 2nd Feb 2016 09:32
Hi to all.
I have little problem with collisions.

The player walk towards the enemy, the enemy it's stopped (IDLE) [Image A]
The player hits the enemy [Image B]
using the up or down Keys, the player slips around the enemy.

I use this simple code:

hit = GetSpriteCollision ( Plr_coll , Ene_coll )

if hit = 1
Plr_y = old_posy
Plr_x = old_posx
endif
inside the function of collisions, the Player stop correctly in front of the enemy, but does not slide towards up or down.


If I use the code:

hit = GetSpriteCollision ( Plr_coll , Ene_coll )

if hit = 1
Plr_y = Plr_old_y + vel_plr_move_y *1.2
Plr_x = Plr_old_x
endif

The player slips around the enemy, but if the player walk on the side below (down), gets inside the enemy (overlap).

I do not know how to detect the collision: Left, right, up and down

Sorry for my english.

Thanks for any Help!

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Feb 2016 09:34
Post up some code and we'll be happy to take a look. A simple way to achieve what you need might be to keep the player's x/y position stored from the previous frame. If a colision is detected, then move the player back to the previous position. Or, you could set the sprites up as dynamic box2d objects and use the built in physics system to look after the collisions.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 4th Feb 2016 10:13 Edited at: 4th Feb 2016 10:17
Thanks CJB

This is the sample code ...

when mario collides (hit) block remains attached.

It's many days that I try to fix it, but it does not work.

This is the correct result ....

Attachments

Login to view attachments
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Feb 2016 11:58
Hi Diegs.

This probably isn't the best solution, but it gets the job done:



V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 4th Feb 2016 12:35
It's work fine, the only problem is the my long code ....

My function structure is this:



I don't know how to integrate your code with mine ....

Again thanks for the BIG help!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Feb 2016 12:41 Edited at: 4th Feb 2016 12:41
In my example, you'd need to split out your x / y movement into seperate collision checks. So your structure would be more like:

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 4th Feb 2016 13:30
Yes.
the problem it's the big structure ...

if I split the code in X and Y I have to call 2 times a collision with objects.

The object strusture is an array (tilemap based) and this touch the fps (surely there will be a reduction of fps) .

It's hard situation ....
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 4th Feb 2016 15:40
I'm not sure, but I may have solved with your code...
Now I test it!

THANKS FOR HELP CJB!
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Feb 2016 16:49
@Diegs : I'm interested by your solution if it works
AGK2 tier1 - http://www.dracaena-studio.com
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 4th Feb 2016 22:51
I use the code of CJB.

I change only my structure!



It seems to work well!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Feb 2016 23:45
@Diegs: I hope they are just placeholder graphics! Lol. If not, Boo might come after you! Haha.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 5th Feb 2016 07:26
@diegs : ok, but you check 2 times the collisions in your structure, this doesn't decrease or touch the fps ?
AGK2 tier1 - http://www.dracaena-studio.com
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 5th Feb 2016 10:33 Edited at: 5th Feb 2016 10:37
I do not call 2 times the update objects!



In Function Update_Player() i have only the setspriteposition(Plr, X, Y) command
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 5th Feb 2016 11:37
I think unless you are testing on a ZX81, the inclusion of an extra collision check here and there probably won't hurt performance any. I think AppGameKit can probably handle hundreds of collisions without too much bother.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-11-25 11:49:55
Your offset time is: 2024-11-25 11:49:55