moving in the wrong direction
Posted
by
Will
on Game Development
See other posts from Game Development
or by Will
Published on 2012-08-26T12:55:43Z
Indexed on
2012/08/27
21:57 UTC
Read the original article
Hit count: 174
Solution:
To move a unit forward:
forward = Quaternion(0,0,0,1)
rotation.normalize() # ocassionally
...
pos += ((rotation * forward) * rotation.conjugated()).xyz().normalized() * speed
I think the trouble stemmed from how the Euclid math library was doing Quaternion*Vector3 multiplication, although I can't see it.
I have a vec3 position, a quaternion for rotation and a speed.
I compute the player position like this:
rot *= Quaternion().rotate_euler(0.,roll_speed,pitch_speed)
rot.normalize()
pos += rot.conjugated() * Vector3(0.,0.,-speed)
However, printing the pos to console, I can see that I only ever seem to travel on the x-axis.
When I draw the scene using the rot
quaternion to rotate my camera, it shows a proper orientation.
What am I doing wrong?
Here's an example:
You start off with rotation being an identity quaternion: w=1,x=0,y=0,z=0
You move forward; the code correctly decrements the Z
You then pitch right over to face the other way; if you spin only 175deg it'll go in right direction; you have to spin past 180deg. It doesn't matter which direction you spin in, up or down, though
Your quaternion can then be something like: w=0.1,x=0.1,y=0,z=0
And moving forward, you actually move backward?!
(I am using the euclid Python module, but its the same as every other conjulate)
The code can be tried online at http://williame.github.com/ludum_dare_24_evolution/ The only key that adjusts the speed is W and S. The arrow keys only adjust the pitch/roll.
At first you can fly ok, but after a bit of weaving around you end up getting sucked towards one of the sides. The code is https://github.com/williame/ludum_dare_24_evolution/blob/cbacf61a7159d2c83a2187af5f2015b2dde28687/tiny1web.py#L102
© Game Development or respective owner