### Changing Players Orientation per tick in UpdateMove()

Expanding and utilizing the engine via C++.
• 1
• 2

#### Re: Changing Players Orientation per tick in UpdateMove()

JackStone
Posts: 67
Joined: Fri Oct 02, 2015 1:03 am
Irei1as, you sir are a genius! Thank you very much for that!

Your code works great! I have the orientation working perfectly now.

However, I have run into issues with the camera, as you said. I am using a plane at the moment, but even so, as the player rotates the camera, it seems to interfere with the new code that I added to orient the player.

I assume I have to combine the "look" quaternion with the new quaternion that I added, do you have any ideas how I would go about doing this?

My current code is:

Code: Select all

 if (!contactNormal.isZero()) { Con::printf("CONTACTNORMAL %f %f %f", contactNormal.x, contactNormal.y, contactNormal.z); doQuatOrientation(contactNormal); } else { Con::printf("NO CONTACT NORMAL"); Point3F cogvec = Point3F(0, 0, 0) - getPosition(); cogvec.normalize(); cogvec *= -1; doQuatOrientation(cogvec); } 

#### Re: Changing Players Orientation per tick in UpdateMove()

irei1as
Posts: 84
Joined: Fri Feb 27, 2015 5:13 pm
I think that's related to one of the changes of player.cpp since that resource and not directly to the part of code you have.
Inside updateMove(const Move* move) look for:

Code: Select all

if(doStandardMove)
Inside that comes the code for the normal rotation code.
(I just deleted everything related to "TORQUE_EXTENDED_MOVE" in my code so if you're using that then I can't help you, sorry.)

Now, try to replace the doStandardMove branch with:

Code: Select all

 if(doStandardMove) { F32 p = move->pitch * (mPose == SprintPose ? mDataBlock->sprintPitchScale : 1.0f); if (p > M_PI_F) p -= M_2PI_F; mHead.x = mClampF(mHead.x + p,mDataBlock->minLookAngle, mDataBlock->maxLookAngle); F32 y = move->yaw * (mPose == SprintPose ? mDataBlock->sprintYawScale : 1.0f); if (y > M_PI_F) y -= M_2PI_F; if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->isFirstPerson()))) { mHead.z = mClampF(mHead.z + y, -mDataBlock->maxFreelookAngle, mDataBlock->maxFreelookAngle); } else { mRot.z += y; //quat rot {...} { //Get a quaternion of our desired rotation //Apply it to our current orientation //First let's try getting an up vector Point3F up(0.0f,0.0f,1.0f); Point3F rotatedUp(0,0,0); mOrient.mulP(up,&rotatedUp); //rotatedUp should now contain our local up vector //We want a rotation around rotatedUp by what was added to mRot.z radians QuatF rot(rotatedUp,y); mOrient *= rot; } // Rotate the head back to the front, center horizontal // as well if we're controlling another object. mHead.z *= 0.5f; if (mControlObject) mHead.x *= 0.5f; } // constrain the range of mRot.z while (mRot.z < 0.0f) { mRot.z += M_2PI_F; //quat rot {...} { //Get a quaternion of our desired rotation //Apply it to our current orientation //First let's try getting an up vector Point3F up(0.0f,0.0f,1.0f); Point3F rotatedUp(0,0,0); mOrient.mulP(up,&rotatedUp); //rotatedUp should now contain our local up vector //We want a rotation around rotatedUp by what was added to mRot.z radians QuatF rot(rotatedUp,M_2PI_F); mOrient *= rot; } } while (mRot.z > M_2PI_F) { mRot.z -= M_2PI_F; //quat rot {...} { //Get a quaternion of our desired rotation //Apply it to our current orientation //First let's try getting an up vector Point3F up(0.0f,0.0f,1.0f); Point3F rotatedUp(0,0,0); mOrient.mulP(up,&rotatedUp); //rotatedUp should now contain our local up vector //We want a rotation around rotatedUp by what was added to mRot.z radians QuatF rot(rotatedUp,(-1)*M_2PI_F); mOrient *= rot; } } } 
After that you should have these lines of code:

Code: Select all

 delta.rot = mRot; delta.orient[1] = mOrient; //quat rot delta.rotVec.x = delta.rotVec.y = 0.0f; delta.rotVec.z = prevZRot - mRot.z; if (delta.rotVec.z > M_PI_F) delta.rotVec.z -= M_2PI_F; else if (delta.rotVec.z < -M_PI_F) delta.rotVec.z += M_2PI_F; 
So be careful and don't replace too many lines. Maybe you should make a safety copy of the file before doing the changes.

But... I'm not sure if that change will be enough, sorry. In my code I use doQuatOrientation before that "if(doStandardMove)" (it's the first line in the update move as my gravity is a variable of player class and not just normals) so it's kind of different. I guess you could copy (with different variable names) the part of finding the normal at the start of the function if needed.

By the way, the camera problem I mentioned is related to motion sickness. If the geometry of the terrain is irregular the camera jumps wildly around when moving with contact surface.

Edit: Also, check for the pack unpack functions. It seems player has two pairs of each and you need to do the mOrient thing in both unlike once as the resouce points. It must be that before there wasn't that many.

#### Re: Changing Players Orientation per tick in UpdateMove()

JackStone
Posts: 67
Joined: Fri Oct 02, 2015 1:03 am
Hi,

Thanks again for your help. I am using standard move, and the code you posted *almost* fixed the issue. The camera is stable, but now, for some reason, the players head moves by itself to face a particular direction, and every time I move the camera, it return to that same spot.

So there must be something causing the player to move their head? It's not the doQuatOrientation code, I checked that.

I'm also having issues combining the move vector (the actual player movement) with the gravity vector. The two vectors seem to cancel out at certain points. making the player unable to move.

I am currently combining them simply by adding them and normalising:

Code: Select all

 Point3F m = Point3F(move->x, move->y, move->z); gravvec += m; gravvec.normalize(); VectorF acc(gravvec); 
This, again, *almost* works, but the direction of the players movement along X and Y changes as their orientation changes.

I just saw your edit about the pack/unpack, I will have a look at that tomorrow. I am slowly making progress with this, thanks again!

#### Re: Changing Players Orientation per tick in UpdateMove()

JackStone
Posts: 67
Joined: Fri Oct 02, 2015 1:03 am
Alright, the camera issue is fixed.

I now just have one issue left, and that is that the players movement direction changes when their orientation changes. IE, pressing the forward key when the player is oriented with Z-Up moves them forward, but when Y is up the forward key moves them in a different direction.

Do I need to somehow rotate the move vector by the mOrient quaternion?

#### Re: Changing Players Orientation per tick in UpdateMove()

JackStone
Posts: 67
Joined: Fri Oct 02, 2015 1:03 am
I actually got this working, it turned out to be so simple.

I just needed to change:

runAcc.z = 0;

to
runAcc.z = runAcc.z * mDataBlock->airControl;

Inside:

else if (!mSwimming && mDataBlock->airControl > 0.0f)

That enables full 3D rotation and movement.

This is pretty cool, I can walk all around any object in 3 dimensions now.
• 1
• 2

#### Who is online

Users browsing this forum: No registered users and 2 guests