[SOLVED]reparentTo question

OK, so i have a camera and i reparented it to my player so when i move it it will move with it. The thing is not only the location but also the rotation is assigned to the camera, and i dont want that (when my player rotates camera rotates too).
Is there any way to limit that? (only location, not rotation)

Parent both your camera and your player to a common node. When you move your player, move that node instead. When you rotate your player, rotate the player.

David

I made a quick example. Note that the parent node is directly above your character!

I get what you mean. Whats a common node? Hidden?
There probably is another way, like
player = Actor(‘whatever’)
player.setPos(x,y,z)
playerpos = player.getPos()
camera.setTarget(playerpos)
Or something like that…

Dude, that’s not necessary. If you have the player and camera children of the same rig, they will move together and the camera will always look at the main character.

pseudocode:
render.attachnewnode(parentnode)
character.reparentto(parentnode)
character.setZ(parentnode.getz()-20)
camera.wrtreparentto(parentnode)
camera.lookat(character)

With this setup, you can accomplish three cool things (like in the movies!):

  1. move and rotate character by moving the character’s node
  2. pan the camera by moving the camera’s node around with intervals
  3. move and rotate the entire scene by moving the parent node

Do what David said to do this stuff!

Ill try this again…
I have an orbiting camera that rotates when you move the mouse. I have a player model that walks on a terrain. I want my camera to follow it (x,y,z) but not rotate with it.

Now Im asking what should the master parent node be? Single vertice geometry set to be invisible or is there a wiser way?

It could be an empty node created on the fly.

aNc = render.attachNewNode('actorNcam')
a=Actor(....)
a.reparentTo(aNc)
camera.reparentTo(aNc)

If you want to move, don’t move a, but move aNc instead :

aNc.setPos(....)

and if you want to rotate the actor, rotate a :

a.setHpr(....)

Then on moving aNc, if you want to use actor’s orientation :

v = Point3(0,1,0) # forward
aNc.setPos(a, v*speed)

Oh so thats how you make an empty node.
Im using the code from Roaming-Ralph
Now I have a parent node, an actor node which is a child of that parent node. And a camera which is a child of the parent node as well.

Well you guessed my next question.
sorry dont quite understand the code.
If i rotate the actor instead of the parent node, i will move only in a straight line. I can do something like this:

 if (keyMap["left"]!=0):
        actor.setH(actor.getH() + elapsed*200)
        parent.setH(actor.getH())
    if (keyMap["right"]!=0):
        actor.setH(actor.getH() - elapsed*200)
        parent.setH(actor.getH())
    if (keyMap["forward"]!=0):
        parent.setY(parent, -(elapsed*8))

but then it gets assigned to the camera too, because its a child of the parent, so… its the same result

That’s because you also rotate the parent node. Don’t do that.

Without those lines it doesnt work too.

    if (keyMap["left"]!=0):
        actor.setH(actor.getH() + elapsed*200)
    if (keyMap["right"]!=0):
        actor.setH(actor.getH() - elapsed*200)
    if (keyMap["forward"]!=0):
        parent.setY([b]actor[/b], -(elapsed*8))

should have been like this. Fixed.

Try this :

    if (keyMap["forward"]!=0): 
        parent.setPos(player, Point3(0,-elapsed*8,0))

thanks.
but its already working anyway