Hello (here I am with an other question)
The goal: if the player is walking and mouse (camera control) is moving left or right then the player will continue walk changing hi heading like the camera.
I thought that it will be easy to perform by a simple:
but apparently not.
The result is a strange behaviour with the player orientation which is not perpendicular to the ground anymore! It’s like I’ve changed the whole HPR while I’d only modified the heading!
I can’t understand why and this is blocking me for going further!!!
Did anyone faced the same thing ?
If ll you do is rotating the camera the same amount as the player, then unless the players and cameras position is exactly the same you wont get good results.
A crude sketch:
The red thing is a player the green a camera (with it’s view), before and after rotating 90deg.
I’ve found that reparenting the camera to the avatar works quite good for a simple camera. You just move the avatar and never even touch the camera. Changing the angle of the camera is then just a mater of changing its position relatively to the avatar and calling LookAt.
Your approach is the very first one I tested and is also leading to other questions but maybe I would have explained how I set up my camera system at the begining
I attached and reparent an empty to my player. Then, I reparented the cam to the empty and here I played with some lookAt(myPlayer) . All this is working perfectly when I rotate my mouse.
1 - The problem is when I’m adding the line:
then everything is turning bad as explained in my first post!
2 - Wezu’s post brings an other question:
How to reparent an object to an other for the location only (not the rotation) ?
reparenting changes the parent only, the local transforms relative to the parent are untouched , but since the parent usualy has different ones it will affect the node you parent around,too.
if you want to keep the node in place (and in rotation) you can do
i cant really follow your exact setup. but usualy things look like this
or if you want the camera to be able to rotate around the player.
the dummy is in the same spot as the player, the camera is moved into the spot you want. you propably want to rotate the dummy in this case.
This is exactly my situation where problems start when I want to rotate the player without rotating the cam!
for example, let’s assume I’m pushing the left button and I want my player to walk left direction but camera keep filming forward (doesn’t rotate), I used this which works:
But after that, when I’d like to go forward again (the same direction camera is filming), I should then obviously use something similar to :
and here the result is a disaster
Some will suggest to rotate the player again by 90 degrees but one of the goals here is also to make the player rotate as the camera while he’s walking…
I mean one of the things I’d like to do is assigning the camera direction when the player is walking, like this if the mouse is getting moved --> then the player will continu walking following the new heading of the cam.
you can set rotations relative to other nodes.
you can do
this way you can set the dummynode rotation independantely. if you want it to follow the player rotation just omit the render part. this also works for rotations relative to the node itself
Hmm… What about something like this:
baseNP = render.attachNewNode(...)
# Or attached wherever makes sense in your project, presumably
player = ...
# set up your player, for example loading a model
# Now, when you want to turn the character, turn "player":
# When you want to move the player, do so by moving baseNP,
# not player.
# Try this; if it doesn't work, you might end up
# doing it "manually":
baseNP.setPos(player, Point3(0, someDist, 0))
#When you want to rotate the camera, just rotate it:
Note that you might have preferable results by placing a node or two between the camera and baseNP, allowing you to, for example, offset it more easily, I think.
I do it like this, and never bother about the camera again (not even if something gets in the way and you can’t see a thing ):
As simple as cheese.