Asteroids-like collision detection/physics & rounding speed
Basically there are two problems. The first one is easy (in a 2D world):
The entities in the project have positions stored as float points. But a screen has only ints as pixels. So, is rounding floats to ints appropriate? Since if I just take the floor, the objects move sloppy (stays the same, then jumps, stays the same etc). What would you do?
The second one not so easy:
So, let's say the players (spaceships) have position, rotation, scale and a center. If a player touches the screen borders, it should bounce realistically. For example:
assume the player looks like a giant 'U'.
if it's rotated 45 degrees to the right and collides with the top, like
Code:
__________
X
/
/
/ C /
\ /
\/
(Where X is the point of collision and C the mass center of the object)
In this case, the point X is a bit to the right of C, so the object should rotate a bit to the right and be pushed down.
There is a force acting directly down from point X (ignore friction for now). How should I implement this?
So, the basic idea is implementing forces with a position and direction. But how to calculate the resulting rotation/translation of the object? I think this needs some trig. Don't matter.
My ideas are:
If the force's direction vector points to the center of an object (beginning at the force point), the translation is equal to the direction and the rotation is none. But if the vector points 90 degrees to the left/right, the translation is none and there is only rotation.