# Rotate orient around velocity vector

## Recommended Posts

Does anyone know how to rotate an object around its velocity vector while it is still pointing into the direction of its velocity in vex? Maybe it is easier in vops, but it would help me understand better the underlying math behind it with vex.

##### Share on other sites

Are you using "@v" and "@up" to orient your object, or "@orient"?

##### Share on other sites
10 hours ago, dandeentremont said:

Are you using "@v" and "@up" to orient your object, or "@orient"?

• 1

##### Share on other sites

Well, if you have just the @v and @up, it's not the most ideal to create a spinning around v axis, because the orientation tends to get wonky when the v vector gets near the up vector. Either way, here's a poor man's setup I use:

```//This method may result in fast flipping if the particles do loop-de-loops

//v@up = {0,1,0};//set this if you don't already have an up attribute
vector forward = normalize(v@v);

//create a quaternion rotating about the forward axis over time
vector4 rotQuat = quaternion(@Time*10, forward);

//use qrotate to rotate a vector by the quaternion
v@up = qrotate(rotQuat, v@up);```

Using @orient is better because you don't have to worry about zero velocity situations or up vectors, but it requires some extra setup during the sim process (Assuming it's POPs)

Edited by dandeentremont
simplified code
• 1

##### Share on other sites

thank you dan and ultraman. I am using @orient.

I ended up using a matrix rotate (in vops) along the velocity vector with a random rotation per id, then converting it to a quaternion. The vex approach you posted makes a little bit more sense. Im going to give it a try! I need to brush up on my linear algebra lol.

thank you so much again!

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account