0
\$\begingroup\$

I have a motorbike which moves along based on a direction vector, I set its forward direction to the direction it's moving.

What I'd like to also do with it is have the motorcycle tilt in the direction it's turning, I haven't had much luck figuring this out though, any ideas?

\$\endgroup\$
1
\$\begingroup\$

Take the cross product of those two vectors (turning direction and current forward direction). Assuming your bike is riding on the XZ plane, if the vector points upward (y is positive) then the bike should tilt left, if it points downward (y is negative) then it should tilt right. The magnitude of the vector probably represents how "big" the tilt should be, but I haven't tried it.

For example, if the bike is currently facing down the negative z axis, the forward direction will be:

{0,0,-1}

If you want to turn 90 degrees right, the turning direction vector will be:

{1,0,0}

If you want to turn 90 degrees left, the turning direction vector will be:

{-1,0,0}

If you calculate the cross products for both left and right turns, they look like this:

Right turn: {0,0,-1} x {1,0,0} = {0,-1,0} 
Left turn: {0,0,-1} x {-1,0,0} = {0,1,0}
\$\endgroup\$
  • \$\begingroup\$ Thanks Tom, that worked exactly as you described and from what I can see the magnitude of 'y' is representing the size of the turn. I uploaded a video to show it working, the bike in front of the players tilt is determined entirely by the y component of the resultant cross vector of the previous and current direction: youtube.com/watch?v=Y_L673dAO8A&feature=youtu.be \$\endgroup\$ – meds Nov 17 '12 at 6:38
  • 1
    \$\begingroup\$ @meds No problem. It looks awesome. \$\endgroup\$ – Tom Dalling Nov 17 '12 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.