# Correct approach to using vectors to move objects around

I want to understand how to move things around using vectors, I have been used to just adding to position.z for example, and i’ve played around a little with vectors but I don’t know the correct way things should be done.

I know the vector object has:

``````.multiply ( v : Vector3 )
.multiplyScalar ( s : Float )
.multiplyVectors ( a : Vector3, b : Vector3 )
.add ( v : Vector3 )
.addScalar ( s : Float )
.addScaledVector ( v : Vector3, s : Float )
.addVectors ( a : Vector3, b : Vector3 )
``````

But I’m not sure when to use which, i’ve read 3D Math Primer for Graphics and Game Development, so I know the concepts of adding and subtracting vectors to move objects towards targets, I also understand the dot product and cross product.

The problem I have is how to put the concepts into practice, like if you want to add a velocity to an objects position, should this be a vector and should it be normalized then multiplied by a scalar to speed it up, seems so many different ways.

If I want to learn about steering behaviours, I know I must apply other forces to avoid obstacles for example, should these also be vectors and should I be adding them to a target vector for example?

Any help on the basic approach to using vectors to move objects around would be appreciated, I’m willing to put in the effort once I know the right approach.

Steering behaviors are in-depth explained in a lot of resources. However, for very simple use cases it is not always necessary to work with forces but with just velocity. You could derive a custom class from `Object3D` and then add an additional `velocity` property (of type `Vector3`). Instead of directly updating the position vector, you just modulate the `velocity` vector in your application and then call the following method per simulation step:

``````update( delta ) {

// calculate displacement

displacement.copy( this.velocity ).multiplyScalar( delta );

// calculate target position

// (optional) update the orientation if the vehicle has a non zero velocity

if ( this.getSpeedSquared() > 0.00000001 ) {

// this will ensure your entity always looks along its movement direction

this.lookAt( target );

}

// finally update position

this.position.copy( target );

return this;

}
``````

We from the Yuka team developed a lot of code in this context including steering behaviors. The above code is part of MovingEntity. The Vehicle class represents game entities using a more advanced locomotion model based on forces and steering behaviors. Check out the steering behavior examples at this site to see this stuff in action.

Thank you I’ve looked at the docs and examples from Yuka, a lot of good work there.

I’ll use these examples to learn from, and more than likely use this library in the future.