- Home /
How can i make the transform rotation Quaternion.identity but smooth ?
The transform is a moving object that move to the targetPosition.
if (Physics.Raycast(transform.position, baseTarget.position, out hit, 100))
{
transform.rotation = Quaternion.identity;
}
What i want to do is:
When the transform is above the baseTarget no matter what height change the rotation to Quaternion.identity but make the transformation of the rotation smooth like lerp or slerp. Now what it does it's like jumping to the Quaternion.identity rotation. I want to see the transform changing slowly/smoothly to this rotation.
And i'm not sure what is the 100 number present ? The height when the transform is above the targetBase ?
And i'm not sure really what is the identity. But this is the rotation i want to transform to be just to get to this rotation smooth and slowly and not to jump to this rotation. It's jumping to the Quaternion.identity.
I tried something like this now:
if (Physics.Raycast(transform.position, baseTarget.position, out hit, 100))
{
var str = $$anonymous$$athf.$$anonymous$$in(.2f * Time.deltaTime, 1);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, str);
}
It's starting the rotation but not complete it. I guess it's too slow. So i'm not sure how to calculate automatic the needed str value.
And yet not sure what is the 100. I set it to 100 since i think it's the height to start the rotation when the transform is above the targetBase.
Answer by EpsilonQoppa · Jun 25, 2017 at 11:12 PM
Well, for starters the '100' being passed to the raycast is the maximum distance of the ray cast.
As far as your rotation not completing..
If you're looking for a specific rotation, or a rotation limit, you can call a coroutine and use a while loop to Lerp so long as the rotation is less than your desired rotation.
If you don't have a specific rotation that you're looking to hit, you're just going to have to have to tune it to turn at the rate you want it to turn.
I posted my last comment to you as answer since i wanted to add the whole script i'm using with some more explaining. I'm not sure if i put the rotation part in the right place in my script and ot sure yet how to do the whole landing and the rotation part. But i'm close.
Your answer
Follow this Question
Related Questions
How can i Instantiate on the terrain from left to right ? 0 Answers
Why the tile map scripts take almost all the cpu usage ? cpu usage is getting to 99% at times 1 Answer
How can i rotate object by pressing on key R and keep object facing to me my self ? 0 Answers
How can i spawn new gameobjects to be inside the terrain area ? 2 Answers
How can i change vertex posiiton to push it back -1 on z ? 1 Answer