chandlerprall / GoblinPhysics

Collision Detection & Response in JavaScript
http://www.goblinphysics.com
Other
147 stars 18 forks source link

How to use linear velocity?? #39

Closed Druidhawk closed 9 years ago

Druidhawk commented 9 years ago

I was hoping to use a physics shape to act as, say a missile. I am trying to manipulate the linear velocity of a physics shape, which has a associated threejs mesh, and move from threejs launcher towards another threejs shape. I wanted to use physics so the arc/curve of the missile track would account for mass etc. Unfortunately whenever I mess with linear velocity I end up with NAN. Since the target shape is moving, I reset linear velocity on the fly, this is a guided missile which tracks its target.

Any thoughts or opinions welcome. I got the idea of velocity from the mesh statue example where you shoot spheres out with a y velocity.

Alternately can I set some kind of attractive force between the missile and a target

chandlerprall commented 9 years ago

How are you setting the velocity? It should be something like

body.linear_velocity.set( 1, 2, 3 );
Druidhawk commented 9 years ago

May I am incorrect in assuming that negative velocities move you backwards.

chandlerprall commented 9 years ago

The velocity is always in world coordinates and not related to the object's rotation. Negative velocities will move an object along the negative direction of an XYZ coordinate.