i am about to code my own collision detection. So this is how it works:
- my object casts a move event.
- my world / collision manager listens for the move events of all movable objects and checks if they move.
- if they move i check for collision and resolve them
now the thing is that the movement speed of my object changes sometimes in the following code:
private void OnObjectMove(StaticObject MovingObject)
{
if(maskCollision(MovingObject))
{
Console.WriteLine("===============================");
Console.WriteLine("movementX: " + MovingObject.movement_Y.Speed + " movementY " + MovingObject.movement_Y.Speed);
resolveMaskCollision(MovingObject);
}
}
and the beginning of my resolve collision method:
private void resolveMaskCollision(StaticObject collidingObject)
{
Console.WriteLine("movementX: "+collidingObject.movement_X.Speed + " movementY: " + collidingObject.movement_Y.Speed);
.
.
.
so and example output is:
movementX: -8,700003 movementY -8,700003
movementX: 0 movementY: -8,700003
As you can see my movementX changed for some reason...
the output is most of the times the same but sometimes it is not and then all my methodes throw exeptions because i dont expect the speed to change there. Now my only explaination for the change of the objects speed is that the event runs on a seperate thread. Is this true? How can i wait for the event? And is it clever to wait for it if it is possible? Or would it slow down my code? (i could either call the methode from my movingObject somehow. But then it would have to save the world/collisionmanager -object)