Sprite velocity and collision

Started by
2 comments, last by micco 21 years, 9 months ago
Hello, I am having problems with sprite velocity and collision detection. I have asked several people and nobody can seem to find a solution. Ok well a sprite when travelling at high speed across the screen for example. The high speed means that it will be skipping maybe 10 pixels at a time in its travels (lower speeds mean less pixels skipped at a time). So what happens if there is a wall within 10 pixels. The sprite will just skip 10 pixels and end up on the other side of the wall. This is wrong since I want the wall to be able to stop the sprite from moving. Can anyone give me a realistic answer on how to overcome this problem. I would be grateful for any useful information. Thanks
Advertisement
Calculating position based on time rather than update intervals (not really that much different, except for that it might permit a slightly higher level of precision) might be beneficial to your case.

Alternatively, you might compute a vector upon which the object is travelling, and find out in advance how far it can traverse upon that vector before something blocks it. Of course this poses problems for colliding with dynamic objects (which the pre-calc would not compensate for), but you might consider hit-testing more often, and reducing the number of pixels your objects move per update.



MatrixCubed
http://MatrixCubed.cjb.net

Instead of testing for collisions with the new position, test for collisions using the area you moved over as well. If theres a collision in the area then move your object backwards until you find the initial collision point. And then decide whether to bounce/die/splat etc..

OT
A more simple method, less mathematical, but also a bit slower, is to check for collisions each pixel the sprite moves, instead of each frame. So if you find out the sprite should move 10 pixels to the right per frame for example, move the sprite one pixel (do not draw it yet however), check for a collision: if there is, make the sprite explode, bounce or whatever, and if there is no collision, move the sprite another pixel and check again, until you''ve moved 10 pixels (And then after that draw the sprite).

This topic is closed to new replies.

Advertisement