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!
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.
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()
heading = base.camera.getH()
pitch = base.camera.getP()
headingradians = heading * (math.pi / 180.0)
pitchradians = pitch * (math.pi / 180.0)
x = 18*math.sin(headingradians)
y = 18*math.cos(headingradians)
z = 18*math.sin(pitchradians)
print " "
if name == "topEdge":
elif name == "bottomEdge":
elif name == "leftEdge":
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!
as stated above you just pass it the nodepath for “local” movement, since the camera is just a nodepath you could just…
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
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
U don’t know how much help you have done to me