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 / Sprite collision. Sliding along a wall.

Author
Message
Thomas John Gorham
6
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 26th Aug 2020 11:28
HI Guys,

Could someone give me a quick example of how to handle collision with walls in a topdown 2d game. At the moment Im recording the old X and Y position of the sprite and moving it back to those positions after a collision. However I cant get it so that you can slide along a wall. I,E, pressing up and forward and running into a walll in front, and still moving sideways but not forward.

I hope that makes sense.

Any tips?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Aug 2020 21:12 Edited at: 28th Aug 2020 21:21
with your other thread, you may want to look at this thread where my hunch is that the issue is related.

otherwise, i tend to use box2d where i can. using some of the sprites from your related thread:

some might jeer about the technique but i think it's appropriate for what you're trying to do

add, just noted this was in 2D and there's nothing wrong with that but since it's AGK-specific, i'd like to move it to the Newcomer board, if you're ok with that? it will get more, appropriate exposure there (IE, you might have received a quicker response if it was).
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
Thomas John Gorham
6
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 30th Aug 2020 01:12
Thanks very much for the reply.

Yes feel free to move to wherever you feel is the right place.

There are so many things you did differently that I need to learn. For example even in the first lines.

WallImg = LoadImage("wall.png")

I didn't know you could name a variable and load the image in the same line, does it automatically assign the number and you dont have to think about it?

Also I didn't know you could put multiple instructions per line with a Colon :

Lastly, I havent been using the inbuilt physics for collision, could you show an example of the same thing without physics sprites ? Or maybe I should start again and use physics.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Aug 2020 04:40 Edited at: 30th Aug 2020 05:20
Quote: "does it automatically assign the number and you dont have to think about it?"

exactly. AppGameKit will assign an unused ID for you. it's a preference "so i don't have to think about it" while some prefer to make the assignment manually (still).

Quote: "multiple instructions per line with a Colon"

it helps me keep related stuff together and also reduces line #s (where i struggle/"can get lost" beyond ~500 lines-worth). IE, a personal preference for structuring code, as above.
a CON would be when i get an error on a line # which contains 5+ instructions, but i deal with it (i've got some stuff with 5k-10k lines that i can "manage" if i stay familiar with it)

Quote: "could you show an example of the same thing without physics "

what you had in the other thread should work, IMHO. OldX#, OldY# = how we used to do it in DBPro but AppGameKit seems different. and, that's why i pointed to the other thread (redefining the bounding boxes) as a "work-around" to whatever floating point/issues are present. some, apparently, know how to deal with it and retain the "sliding collision" approach while, if i'm going to do "something more", it's going to be box2D.

ADD: See here for another work-around that you might prefer.
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
Thomas John Gorham
6
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 30th Aug 2020 11:12
Hi Virtual Nomad!

Thats really smart, I think I will start using some of your techniques in my coding style.

For the collision I dont think its a floating point error.

I can get it so that the character slides, but when they get too a part of the wall that is adjacent to another wall (i,e colliding 2 walls at once) I cant get it so that the slide continues, it awlays stops.

I've attached my current code which works, but it doesnt slide.

If you have time want to have a look?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2020 14:30
AABB sliding collision will be one of the simplest you can implement. The math changes just a little when the walls are rotated to any angle, but in 2D it's still not overly complicated.

How far you slide depends on the angle at which you hit the wall. So if point A is where you character would move if unobstructed, but there's a wall there, point B is where it actually ends up. The movement forms a right triangle. Hopefully my poor illustration shows you how the sliding works based upon the angle of impact.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Thomas John Gorham
6
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 4th Sep 2020 11:03
oh nice!

That looks really cool.

Thanks for the example!

Login to post a reply

Server time is: 2024-11-23 08:25:36
Your offset time is: 2024-11-23 08:25:36