# moving actor in direction of hpr

Hello fellow Panda3d programmers!

I am no math scientist and i am trying to move my actor model in my game. The problem is i want to move the actor the same direction as my actor is heading. I cant see any easy way of doing this. Is there a metho that could help me or is there any relativly simple script i can use in my code???

Any help would be just great!

Try:

actor.setPos(actor, 0, 5, 0)

This moves your actor five feet along the y axis relative to his current position, which is to say, five feet forward, whichever way he is facing.

David

1 Like

Thank you david!

It was exactly what i needed!!

Iâ€™d like to dig up this old thread to ask a related question:

How would I be able to move the camera in the direction of its orientation?, or for that matter to its right or to its left. I have been trying a million different ways and none seem to be valid. My latest attempt is parenting base.camera to a new ActorNode which I use to apply a velocity in the (hopeful) direction that the camera is facing. Here is my function that is called when a mouseWatcherRegion event is thrown:

``````
def moveCam(self, foo, blah):
#this is what base.camera is parented to:
cam_PO = self.cameraActorNode.getPhysicsObject()

name = foo.getName()
pitch = base.camera.getP()

pitchradians = pitch * (math.pi / 180.0)

print self.cameraNodePath.getPos()
print " "

if name == "topEdge":
cam_PO.setVelocity(x,y,z)
elif name == "bottomEdge":
cam_PO.setVelocity(-x,-y,-z)
elif name == "leftEdge":
cam_PO.setVelocity(x,y,z)
else:
cam_PO.setVelocity(x,y,z)
``````

This unfortunately doesnâ€™t work because it does not move the camera forward (Itâ€™s relative Y axis) when I want it to after Iâ€™ve rotated it!

Thank you so much in advance!
-RC

as stated above you just pass it the nodepath for â€ślocalâ€ť movement, since the camera is just a nodepath you could justâ€¦

``````
camera.setPos(camera,0,5,0)``````

if you wanted to move ahead 5 meters in the direction of the facing:P

I tried doing it w/o that, you know right triangles and all, but failed horrifically(my geometry skills must be lacking) heh

Hello,

It is normal that the moving in the direction of hpr (with a.setY or a.setPos relative to the object to be moved), the distance to be affected of the dimension of the object? I think the new distance is calculated from the bound of the object, not from the position point.

You can try this scaling the object to different dimensions and see that the new Y is different.

I need the new Y to be constant with the speed, not dependent of the size of the object. How to achieve this?

After you scale the model call flattenLight()on it. It will apply(bake) the transforms onto the models vertices. Then you can move it, and it will react as if its scale was never changed.

Thank you man