[bge][help] Camera movement

Hi,

I am working on a RTS style game and i want the camera to move but with

 cam.setLinearVelocity([0,1,0], True)

it doesnt work.
It works with

cam.position.x = cam.position.x + 0.1

But when i rotate the cam it does still move on the X axis.

What is have so far:
rts.blend (873 KB)

setLinearVelocity() won’t work unless the object’s physics type is set to Dynamic or Rigid Body (which can be enabled on cameras). However, you probably don’t want to do this since your camera will then be affected by physics.

If you want an object to move along a local axis, you should create a vector directed along that axis and then rotate the vector before adding it to the object’s position.

from mathutils import Vector

# create vector along x-axis
vec = Vector([1.0, 0, 0])

# align the vector with the camera's x-axis
vec.rotate(cam.worldOrientation)

# move the camera
cam.worldPosition += vec

Thanks Mobious it works but i have only one problem left. Is it possible to exclude the x-axis rotation?

It is also possible to exclude X axis rotation:


from mathutils import Vector  
# create vector along x-axis 
vec = Vector([1.0, 0, 0]) 

# get object orientation, to x,y,z coordinates
rot = cam.worldOrientation.to_euler()
rot.x = 0

# align the vector with the camera's x-axis
vec.rotate(rot)

# move the camera
cam.worldPosition += vec

there is a page for math utilities: http://www.blender.org/api/blender_python_api_2_70a_release/mathutils.html#mathutils.Vector

Thanks Jimy Byerley it works!