checking for collision detection
Posted
by
bill
on Game Development
See other posts from Game Development
or by bill
Published on 2013-07-02T04:32:15Z
Indexed on
2013/07/02
5:14 UTC
Read the original article
Hit count: 356
collision-detection
I am trying to create a game where you have a player and you can move right,left, and jump. kind of like mario but its not a side scroller. also i want to use 2d array to make a tile map.
my big problem is that i dont understand how to check for collision. i spend about 2 week thinking about this and i came up with 2 solution but they both have problems.
let say my map is:
0 = sky
1 = player
2 = ground
00000
10002
22022
Solution 1: move the '1'(player) and update the map
less say player wants to move right, then
x+=grid[x+1][y]
this make the collision easy bc you can just check if
if(grid[x][y+1] == 2){
//player is standing on top of ground
}
problem with this when u hit right key player will move (x*Titlewidth) to right. and as you can see the animation wont look smooth.
Solution 2: move player and dont update map
player_x += 2
this will make the animation more smoother bc i am just moving 2 pixels.
problem1: i cant update map bc if player some times will be middle of int(2d array). but thats ok sinces its not a side scroller so updating the map is not a big deal.
problem2: only way to check for collision is to use java intersection method. but then player have to be atleast 1 or 2 pixel in ground in order to check for collision. and as you can see that wont look good too.
plz note this is my first collision game in java. so plz try to explain alot otherwise i wont understand it.
© Game Development or respective owner