Time Based Modelling
sdwWhile the forums seem active tonight I'd like to see if I can get one of my little problems solved. The problem is that sometimes when I give an object too much speed it will run past a solid obstacle. eg: There's a 2 dimensional map array, holding tile values and walkable values. When moving an object it checks to make sure that the tile it's moving onto is walkable first, then it will reset its position to that tile. But sometimes the speed is so great that the object's next position may actually pass over an unwalkable tile to another tile adjacent to it. How can I get around this problem?
BrykovianThe process you're looking for is called "nearing" ... basically, if you have a situation like you describe, you need to walk through a loop of tiny changes from the position the object started in to where it would end moving at its current speed, and do a collision check at each point in the loop. Obviously, you don't draw it after each tiny position change in the nearing loop -- only use them for the checks. -Bryk
SpodiI was gonna say exactly what Bryk did. So, for example, if you moved MX pixels with each tile 16 pixels wide: If MX / 16 > 1 Then For LoopX = 1 To Int(MX / 16) If MapTile(LoopX + UserX, UserY).Blocked = True Then Exit sub Next LoopX End If So for the first part, you check if you need to loop through with loopX. The second part gets the amount of tiles to check (rounded down because moving 1.9 tiles still wont be touchign tile 2 unless your game is on acid). The the part in the loop simply just checks if the tile is blocked, and if it is, it exits the sub - no movement takes place.