Steve_Yorkshire Posted September 14, 2015 Share Posted September 14, 2015 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. Quote Link to comment Share on other sites More sharing options...
JeffR Posted September 15, 2015 Share Posted September 15, 2015 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. Quote Link to comment Share on other sites More sharing options...
Azaezel Posted September 16, 2015 Share Posted September 16, 2015 Tough to tell without a vid, but tried the other one: https://github.com/GarageGames/Torque3D/blob/c152ae86f3f09b3c1d736954b352723d274582f1/Engine/source/scene/sceneObject.h#L469-L475 ? Quote Link to comment Share on other sites More sharing options...
Steve_Yorkshire Posted September 17, 2015 Author Share Posted September 17, 2015 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) Quote Link to comment Share on other sites More sharing options...
Steve_Yorkshire Posted September 17, 2015 Author Share Posted September 17, 2015 http://www.payneful.co.uk/blogsplosion/wp-content/uploads/clouseau.jpgThe 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.