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.

Author
Message
BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 30th Nov 2011 16:56 Edited at: 30th Nov 2011 16:57
Hello everyone, how would I make it so the player would go around the wall and not going through it? The world moves around instead of the player. I have tried some ways but it doesn't seem to work properly, what would everyone else's way of doing this be?

Here's some simple code, how would you add collision so you can go around the wall?

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 30th Nov 2011 17:19 Edited at: 30th Nov 2011 17:21
For 2d... I would use a tiled-world and a multi-dimensional array (usually 3-5 layers). Do a search for tile worlds, tile, tiled worlds, tiled maps, tile-based, tilebased...(not sure which will yield the best results), to see some examples. After getting down the basics you may want to look up techniques for "smooth scrolling" tile-based maps.

~ZENassem
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 30th Nov 2011 18:07
Perhaps check as well... The 2D threads...

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 30th Nov 2011 18:18
so you're trying to create a platform game, you will need plenty of collision points.

my advise to you is to use box 2D, it will make platform games much easier to program.
BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 30th Nov 2011 22:23 Edited at: 30th Nov 2011 22:47
Ok so I've been looking at 2d threads, saying to draw the sprite while a collision check is happening, and to store old locations then moving it back to the old location if a collision has happened, and to do this before the drawing of a sprite. I need to be able to slide around the wall too.

Why doesn't the below code work?



Thanks for the help
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Dec 2011 01:09
Do not put the player in the old position if they collide; instead slide across the direction that has no collision.

In otherwords;

Move left or right; if there is collision; move the opposite way.

Move the player up or down; if there is collision; move the opposite way.

Two dimensions, two collision checks.

Example: If moving towards the bottom right and the collision is to the right, but not down; the player will stop moving right, but will continue moving down; thus sliding down until there is no wall to the right; then the player moves towards the bottom right.

In 3D this works as well; you just do the third collision check; however I have left out how to bounce off of irregular shapes with since this is more complex.

BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 1st Dec 2011 23:39
Hmm I'm not sure what you mean here Chris, a possible code example?

Also how would I do this on per pixel basis, I.E images that are rotated(in the image itself) making some pixels transparent?

Thanks for the help
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Dec 2011 00:03 Edited at: 2nd Dec 2011 00:03
I cannot really test any code right now, so all I can do is edit your code in my web browser.

Old:


New:


Now I must say that your code will not work because Sprite Collision is not pixel based. You could split your level up into individual walls and check collision with all of these. Pixel collision is slow and unrecommended unless you have a small world or special code. I recommend Box2d; not that I have used it, due to working in 3d, but from what it says it does and because of who made it, I'd say it should be good for all 2d games like this. Let the engine do the work while you focus on the other aspects.

BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 2nd Dec 2011 20:16 Edited at: 2nd Dec 2011 20:18
(With some minor edits to your code) it seems to work great.

I think I saw a post a while ago which I can't seem to find anymore about collision on the left, right, top and bottom of a sprite, does anyone know how I can test if one of the sides of the player has collided with another sprite?
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 3rd Dec 2011 03:33
Hi there. If you're looking for something like pixel perfect without the overhead, you might want to consider line collision. This would also allow you to detect things like the point of contact or the line being hit so you can work out which side a collision is occurring from. I wrote the LineMap plugin to try and make this easier to implement so you might want to have a look and see if it would do what you need. As Chris Tate says, I'm sure Box2D would work great too though. I've not used it in DBP either but it seems pretty good for physics at least in AGK. I'm not sure how you'd work out the direction with that but as I say, I've not used it.

Login to post a reply

Server time is: 2026-07-11 06:07:16
Your offset time is: 2026-07-11 06:07:16