So, when an object is moving by itself, the velocity will be add to the object's position. What if the object is moving by the mouse, what would it be the velocity? Would it be "vect2(mouseX, mouseY)" ?

Printable View

- 03-16-2006hdragonVelocity of an object
So, when an object is moving by itself, the velocity will be add to the object's position. What if the object is moving by the mouse, what would it be the velocity? Would it be "vect2(mouseX, mouseY)" ?

- 03-16-2006BobMcGee123
the velocity vector would be the mouse position minus the position of the object.

The magnitude (length) of that vector would be the speed (delta distance per unit time).

Vector3 Velocity = MousePos - ObjectPos; //note that you have to be careful about mousepos, in windows screen coordinates i believe the negative y axis is 'up

Velocity.Normalize(); //make the length equal to 1

Velocity = Velocity * Speed; //speed is just some variable you define

Vector3 FrameMovement = Velocity * dt; //speed is in units per second, so when you multiply speed times the time between frames (dt) that gives you the actual physical movement between frames.