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.

2D All the way! / 2D Collision

Author
Message
jblack
16
Years of Service
User Offline
Joined: 29th Jan 2008
Location:
Posted: 19th Feb 2008 05:58
How would I check for collision with a wall and if this collision happened make the sprite stop and not be able to go past it?

I've attached a bitmap of a board that i want to do this on. All the black is off limits and so is the wall.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Feb 2008 01:54
Looks like your map is tilebased, so it's likely stored in a 2D array, am I right? Checked to see if the tile the player is attempting to move onto is passable or not. Here's a 5x5 grid. In this example, if there's a 1 in that tile then we can't move there, but any 0s would be passable.

1,1,1,1,1
1,0,0,0,1
1,0,0,0,1
1,0,0,0,1
1,1,1,1,1


jblack
16
Years of Service
User Offline
Joined: 29th Jan 2008
Location:
Posted: 20th Feb 2008 03:34
I thought about doing something like that, but that was supposed to be a drastic measure. If you can't think of any other way then I supposed I'll have to do this.
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 21st Feb 2008 21:40
although sureley having an array match up to a map that is of that viewport would be challenging to say the least? maybe im missing the trick
jblack
16
Years of Service
User Offline
Joined: 29th Jan 2008
Location:
Posted: 22nd Feb 2008 05:04
I agree with you Paul. I have no idea how to make him not go through the walls in the isometric view.
Hummanoid Typhoon
18
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Middle of nowhere
Posted: 6th Mar 2008 22:32 Edited at: 6th Mar 2008 22:33
You could have a collision map made from simple sprites (i.e. a solid color) that are invisible and just check the collisions with player.

You could also use the array method but the jaggies might make the player stick to the slopes on you.

0000100000000000000100
0001000000000000001000
0010000000000000010000
0001000000000000100000
0000100000000001000000
0000010000000010000000
0000100100000100000000
0001001010001000000000
0010010001010000000000
0100100000100000000000
0001000000000000000000
0000000000000000000000

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Mar 2008 11:00 Edited at: 7th Mar 2008 14:37
There's 2 options for isometric. The most straightforward one is using the 2D map array as a reference, very fast this method, because it usually just involves checking array locations, nothing fancy.

The other option is using a collision mask, this would be almost a copy of each level object, with the collision areas specified (maybe with a special colour). This holds a lot of benefits, like much more accurate collision. Also, the rest of the image can be used to key other things, like deciding if the player is in front, or behind the object based on the colour of pixel their feet are standing on.

There are a few pixel perfect sprite collision examples around, there's even the Styx plugin, which would be very handy for an isometric game I think.


EDIT:
Just thinking, it would be best to have just a collision version of each level part, for example a wall would have a filled in tile on the ground rather than the whole wall. I'd also have a small isometric tile to act as a collision sprite for characters. Then rely on pixel perfect collision on the special collision sprite, but if the z depth of the level sprite is in front of the player, and there's a collision on the real sprite image, then the sprite image needs to be drawn after the player sprite (might involve simply adjusting the player Z depth value). Zdepth is something I think you should deal with first, get level objects drawing in a sensible order first I reckon (this z depth value can simply be the Y screen location of the sprites hot spot).


less is more, but if less is more how you keeping score?
jblack
16
Years of Service
User Offline
Joined: 29th Jan 2008
Location:
Posted: 20th Mar 2008 01:20
How would I make it so if the sprite was hitting a certain color then they would stop then? my color is rgb 32, 156, 0
Mr Dynamite
16
Years of Service
User Offline
Joined: 7th Feb 2008
Location: A good question
Posted: 31st Mar 2008 21:30
I think i know what your talking about Jblack... you have a tilebased map
11111
10001
10001
10001
11111
any 0s are passable, and any 1s are not
before moving the sprite/dot, you have an old map position, and when moving the dot/sprite, you get your new position

if the map position is equal to that of a wall, make the current map position equal to the old map position
(i.e.
omx = mapx
omy = mapy
if up/left/right/downkey()=1 then mapx/mapy = mapx/mapy -/+ 1
if mapx = wallx(x) and mapy = wally(x) then mapx = omx : mapy = omy)

I used that code(but with a string) to make a 2D game, so mabey it will help you

Login to post a reply

Server time is: 2024-05-06 23:52:39
Your offset time is: 2024-05-06 23:52:39