Jump to content

Player changes view direction after calling setNodePosition


photo

Recommended Posts

Hi, we have two "scenes" within a world, and I want to warp the camera from one scene to the next.  The two scenes are in the same orientation, so I would expect that just moving the camera, the camera would be pointing in the same direction.

 

However, after calling setNodePosition on the camera, the camera is now facing a seemingly random direction.  Why does the camera change direction when I just call setNodePosition.

 

The overall flow of the code goes something like this.

 

 

dvec3 camPos = player->getNodePosition();

 

camPos -= lastWorldPos;  //To move the camera back to the origin from scene1

 

//Does other stuff here...

 

camPos += pos;  //The position of scene 2

 

player->setNodePosition(camPos); 

 

This moves the position to the correct spot, but the camera is then pointing in a funny direction.  Going back and forth between the two points, the position is always correct, but the orientation seems to rotate randomly each time.

 

I added these lines in, just to see if I could fix it:

 

//when I save off the camPos above:

dvec3 camDir = player->getViewDirection();

 

 

//later, when I set the position on the camera:

player->setViewDirection(camDir);

 

This doesn't help.  It's still pointing randomly.

 

Thanks.

 

Link to comment

Ok, I've found the problem... it still doesn't make sense to me, but I've found a workaround.

 

My script was setting the PlayerSpectator phi and theta angles, and even though they didn't change (I printed out theta and phi angles before and after and they were the same), calling setPhiAngle and setThetaAngle after the warp with the same values caused the funny rotation.  So what I did to fix was to export the position to my script and set it in the script rather than in c++.  Then after I change the position in script, I call:

 

phi = player.getPhiAngle();

theta = player.getThetaAngle();

 

So that on the next update loop, it uses the new phi and theta.  That works, but I don't understand why phi and theta changed just from moving my player?  Aren't phi and theta absolute?  Or are they somehow based on the player's position?

 

Thanks

Link to comment

Another similar problem to this is the following scenario.

 

We want to keep the same player position and orientation between worlds.  Each world creates its own player, so my idea was to save off the old position and orientation before the world loaded, and then once the world loaded, set the position and orientation.

 

However, setting the position works, and setting the orientation does not.  I can't figure out why, it seems I'm saving off the correct angles, and setting the correct angles, but once again calling these methods results in what seems a random orientation for the player.

 

Here's the code in my script.  The functions you see below were exported from c++ to pass out the position, phi and theta angles.

 

if (getNeedPlayerPositionUpdate())
{
player.setPosition(dvec3(getNextPlayerPosX(), getNextPlayerPosY(), getNextPlayerPosZ()));
phi = player.getPhiAngle();
theta = player.getThetaAngle();
clearNeedPlayerPositionUpdate();
 
if (getNeedPlayerOrientationUpdate())
{
phi = getNextPlayerPhi();
theta = getNextPlayerTheta();
player.setPhiAngle(phi);
player.setThetaAngle(theta);
clearNeedPlayerOrientationUpdate();
}
Link to comment

I am abandoning the use of setPhiAngle and setThetaAngle, they are just too unpredictable--especially when used in conjunction with setNodePosition or setPosition or setWorldNodePosition.  (See my other post here:  https://developer.unigine.com/forum/topic/3773-playerspectatorsetphiangle-not-working/ I believe these may be the same issue)

 

I'm now using setDirection on the player and it works fine, doesn't randomly rotate on me.

 

For example, if I setPhiAngle(90), the camera is axis-aligned, as I would expect, however after loading a second world, calling setPhiAngle(90) again, the camera is now pointing in a North-Westerly direction, no longer axis-aligned.

Link to comment

Hi Joseph,

 

Sorry to hear that setPhiAngle() and setThetaAngle() are still not working for your needs. Using setPosition also can be tricky in some cases.

 

Is there any chance to take a look at a small sample where we can find such unexpected behavior? According to the dev team setPhiAngle() and setThetaAngle() mehods are working fine. Probably, problem might be somewhere else.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi Silent,

 

Yeah, I've thought about trying to reproduce it in a small sample file for you guys so you could take a look at it.  Problem is, I just haven't had the time to put something like that together!  If things free up soon and I get the time to work on it, I'll send it your way.

 

Thanks.

Link to comment
×
×
  • Create New...