Camera Movement Relative to Rotation

Ok, this has been driving me nuts- how do you move the camera in the direction it’s facing? I have looked at the Normal Mapping tutorial, but I don’t understand how the camera movement works. I have tried moving the camera with sin and cos, but the results could have easily given someone a seizure… :confused:

Here is a snippet of what I was trying to do. I’m foggy on my trig, so I wouldn’t be surprised if I made a blundering mistake.

    def keyboardTask(self,task):;print h
        return task.cont

mvX, mvY, and mvZ are either -1, 0, or 1 depending on the key and if it’s pressed.

Any helpful advice will be greatly appreciated! :slight_smile:

I think that your problem lies in, as I recall, the sin and cos functions taking angles in radians and the getH method returning an angle in degrees.

The simplest solution is probably to convert the value that you get from getH to radians using the deg2Rad function before passing it to the sin and cos functions, like so:

h = deg2Rad(

Trigonometry isn’t necessary to do this, if you just want to dolly the camera you just need to move it on Y relative to itself., <value>)

If you want to move it only on the direction its facing on the XY plane, you can follow the code from roaming ralph, which uses matrices to calculate the movement.

forward =
forward.normalize() + forwards<* multiplier>)

Thanks for both of your replies!

I didn’t know that sin and cos required radians in Python- very good information to know for the future-

That made life sooo much easier! Thanks for the quick reply- it compressed my block of script down to a few lines!