Jump to content

Inherit Rotation Gives The Harlem Shake


Steve_Yorkshire

Recommended Posts

It's late and I've been staring at this for too long and my brain has turned to mush ... :?


I have an object (Aiplayer) which inherits it's rotation from the player. It kinda works except it causes the object to shake like a washing machine on spin cycle, which isn't good for shooting as projectiles go everywhere. Retrieving the initial transform via getForwardVector.

 

//...
   Point3F forward = eye.getForwardVector();
//...
	   Point3F masterVec = mMaster->getTransform().getForwardVector();
 
	   F32 xDiff = masterVec.x - forward.x;
	   F32 yDiff = masterVec.y - forward.y;
 
	   //can we stop the shakes? Not like this we can't :/
	   if (mFabs(xDiff) < 0.001f)
		   xDiff = 0.0f;
	   if (mFabs(yDiff) < 0.001f)
		   yDiff = 0.0f;
 
	   if (!mIsZero(xDiff) || !mIsZero(yDiff))
	   {
		   // First do Yaw
		   // use the cur yaw between -Pi and Pi
		   F32 curYaw = rotation.z;
		   while (curYaw > M_2PI_F)
			   curYaw -= M_2PI_F;
		   while (curYaw < -M_2PI_F)
			   curYaw += M_2PI_F;
 
		   // find the yaw offset
		   F32 newYaw = mAtan2(xDiff, yDiff);
		   F32 yawDiff = newYaw - curYaw;
 
		   // make it between 0 and 2PI
		   if (yawDiff < 0.0f)
			   yawDiff += M_2PI_F;
		   else if (yawDiff >= M_2PI_F)
			   yawDiff -= M_2PI_F;
 
		   // now make sure we take the short way around the circle
		   if (yawDiff > M_PI_F)
			   yawDiff -= M_2PI_F;
		   else if (yawDiff < -M_PI_F)
			   yawDiff += M_2PI_F;
 
		   movePtr->yaw = yawDiff;
	   }
//...

 

Off the top of my head suppose I could drop getForwardVector() and try either getTransform().toEuler() or try and force the rotation with a setTransform update but they hardly count nice methods. :oops:


Any feedback appreciated.

Link to comment
Share on other sites

Hmm, this sounds similar to some cases I've seen with my e/c stuff, when you set the rotation and sometimes it goes all wonky. I've got several functions used for specifically setting the forward vector and stuff to try and counteract rotation oddities but it still crops up on occasion.


No doubt it's juar some weird math, but it's tricky to nail down.


I'm stuck on work crap tonight, but I'll try and give this a real look tomorrow.

Link to comment
Share on other sites

Apologies about having gone swanning off for a few days ...


Here's a vid to illustrate the issue.


ZdJE5QsL2Q8


I also tested feeding the follower an xyz position (the player's so it constantly updates when moving) and this worked fine without the delerium tremors ... so maybe the solution I should be looking for is to extrapolate the a position in space from scaling the player's forward vector ... or something ...


I guess also I could get the player's rotation and just force it into the follower's transform (though that doesn't sound terribly glamourous)

Link to comment
Share on other sites

http://www.payneful.co.uk/blogsplosion/wp-content/uploads/clouseau.jpg

The case is solv-ed

 

Thanks to @doc for the tip, I just needed the getTransform().toEuler() for local X and Y. I'd tried that on the master object but to no avail.

 

Point3F masterVec = mMaster->getTransform().getForwardVector();
 
	   F32 xDiff = masterVec.x - getTransform().toEuler().x; //forward.x;
	   F32 yDiff = masterVec.y - getTransform().toEuler().y;//forward.y;
 
	   //do we need this? It works with it so leave alone
	   if (mFabs(xDiff) < 0.001f)
		   xDiff = 0.0f;
	   if (mFabs(yDiff) < 0.001f)
		   yDiff = 0.0f;
 
	   if (!mIsZero(xDiff) || !mIsZero(yDiff))
	   {
		   //Con::errorf("Follower has master '%d'.", mMaster);
 
		   // First do Yaw
		   // use the cur yaw between -Pi and Pi
		   F32 curYaw = rotation.z;
		   while (curYaw > M_2PI_F)
			   curYaw -= M_2PI_F;
		   while (curYaw < -M_2PI_F)
			   curYaw += M_2PI_F;
 
		   // find the yaw offset
		   F32 newYaw = mAtan2(xDiff, yDiff);
		   F32 yawDiff = newYaw - curYaw;
 
		   // make it between 0 and 2PI
		   if (yawDiff < 0.0f)
			   yawDiff += M_2PI_F;
		   else if (yawDiff >= M_2PI_F)
			   yawDiff -= M_2PI_F;
 
		   // now make sure we take the short way around the circle
		   if (yawDiff > M_PI_F)
			   yawDiff -= M_2PI_F;
		   else if (yawDiff < -M_PI_F)
			   yawDiff += M_2PI_F;
 
		   movePtr->yaw = yawDiff;
        }

 

XvPKU3CNgt8

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...