rotate translate and local coordinates

Hi,

I’m using a joystick to make my characters move. I have a looping animation. I’m changing the HP and Y of the top node of the model with joystick input. I can get them to either translate or rotate really well with the input, but then the other won’t work quite right…I think it’s a case of global vs. local coordinates.

If Translate is working well, the rotate spirals out or in. It seems that where ever I imported the model, it rotates around that point no matter where my character is places.

If rotate is working fine, then I tranlate along one axis instead of along of the Y trans heading of my actor.

Is there a way to force the rotate to use a local rotation point based on where I move it? Please let me know if this is in documentation or if anyone has any ideas on getting it to work properly.

-Brian

Rotate will perform the rotation about the node’s local origin. If you want it to rotate about some other point, you have to use nested transforms. Try creating a new, empty node, and attaching your model to this node. Now you can rotate the top node, and translate the second node, or vice-versa. Experiment with this until you get the effect you are looking for.

David

Hi David,

I curently have nested hierarchy nodes in the file, but that won’t help. If I put the rotate node as the child, and translate as the parent, it obviously won’t go in the direction I turn it. If I do it the other way around, the rotate node stays in the same place as the translate node moves around.

I’ve tried taking the rotation of one node, and then getting the sin and cos of it and multiplying it into the translate node and use that…it sort of works, but not really…I think the amalog input is a little too shaky and makes it go a little crazy…and not really move the way it’s suppose to.

Is there a section in any of the manuals or documents about the Actor and how to get rotational and translational (or does it us one 4x4 matrix?) matrix information and how to then change that information?

Any other suggestions?

I think i’m going forward with the other parts of the game and then coming back to this.

Thanks,

Brian

I guess I need to understand exactly what effect you are hoping to achieve. It shouldn’t be necessary to fall back to using sin and cos, or constructing your own 4x4 matrix; Panda’s rotation and translation tools are adequate to achieve any kind of transformation.

This is not (much) related to the Actor class, which performs the translations and rotations as dictated by its animations. However, if you are using controlJoint() to directly control an Actor’s joint animation, then you will be using Panda’s transformation tools, but it does get complicated and you will have to have a solid understanding of how the transforms fit together.

David

Since the translation is in world space, the rotation needs to be accounted for in that translation. Using a sort of call such as setY(getY+move_length) won’t account for the fact that the node has been rotated at some angle. The children of that node will have a rotated coordinate space (ie: they will move in the direction the node is facing), but that node will still translate in world space.

I think this discussion might help:

https://discourse.panda3d.org/viewtopic.php?p=5486#5486

In short, use one node and translate accounting for the rotation.

OK, I think I see what you’re saying from the other thread.

I need to make some sort of new “dummy” node. I then translate that node. Then I attach my actor to this joint and then rotate it.

Is that it?

If so, I have one problem (or maybe it’s not), I have all my motion in a def statement that’s in a continuous Task since I’m constantly pulling data from the joystick. I’d think if I make a new dummy node, I’d want it to be create outside the def statement and then have the def statement handle all of the node attachment. How do I get the def() to recognize my dummy joint? I tried this a few times and kept getting errors that it didn’t know what “dummy” was. Am I going about this the wrong way?

I’m not a programmer if you couldn’t tell, but at the same time, I’ve done a lot of video game work, just not on the programming side of things.

-Brian

A dumy node should not be needed to move the actor around, and it is possible to do this in one task. This just means moving the actor in two or all three dimensions, not just in the y direction.

In the 2 dimensional case, the actor is moving around on a flat plane. You should only need to change the heading when he turns. You would then take that heading and calculate how much he would be moving in the y direction and the x direction. Using a joystick, which has 2 dimensions, moving the actor would not be too hard. Just take the joystick x and y values, multiply them by some top speed and translate the x and y coordinates of the actor. This assumes when the joystick is centered the input is (0,0) and, depending on the joystick coordinates, you may need to invert the x or y values.
To rotate the actor, just use some trigonometry on the joystick input to find the angle which it should be facing and set the heading to that angle. Finding what that angle is depends on the initial direction the actor is facing when it is loaded.

All of this is performed on the top-level node of the actor.

Then from the example you pointed me to, what’s the “arm”? Is it a joint in the actor or is a dummy node create to trans/rot the actor?

—code—

self.tiny is an Actor

dist = 1.0
arm = render.attachNewNode(‘arm’)
arm.setX(dist)
self.tiny.reparentTo(arm)
arm.setH(angle)
—code end—

I’m going to try to change my methods up a little bit tonight and see what I can get.

Thanks for all the help. This is one of those times where sitting in front of the same computer for 2 minutes could probably solve the problem.

-Brian

Got it all figured out…at least in 2D, but only want height terrain for 3D so that my character can walk up and over hills.

Had to go back and try with something really simple and work the kinks out…about 10 lines and that was that. My problem was that I was trying to rotate and then translate along that vector instead of getting a 2D coordinate and then rotate my character to face that direction and translate him using those coordinates.

Thanks for all the help.

-Brian