#### Archived

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

# Sprite velocity and collision

This topic is 5938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
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 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).

1. 1
2. 2
Rutin
26
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632941
• Total Posts
3009330
• ### Who's Online (See full list)

There are no registered users currently online

×