Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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}
share|improve this answer
    
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 –  zombinee Nov 17 '12 at 6:38
1  
@meds No problem. It looks awesome. –  Tom Dalling Nov 17 '12 at 7:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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