Archived

This topic is now archived and is closed to further replies.

micco

Sprite velocity and collision

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites