- Home /
Why is My Slerp The Derp?
So, I'm attempting to get the object to turn around 180 degrees. I've checked the doc and looked through the previous answers.
From those I've put together this:
public void TurnAround()
{
gameObject.transform.rotation = Quaternion.Slerp
(
gameObject.transform.rotation,
Quaternion.LookRotation(-transform.forward),
3.0f * Time.deltaTime
);
}
It doesn't appear to function, at all - not even the slightest rotation..
What am I doing wrong?
Update 11/13/16: Okay, so here's how they're rotating normally,
transform.rotation = Quaternion.Lerp
(transform.rotation, Quaternion.Euler
(m_CurrentRotation + transform.forward), Time.deltaTime);
To me it literally looks like the same logic with a faster speed and different angle but obviously..
Is your goal to have this happen progressively, over time? Where are you calling this and how often?
Yeah my goal is to have it happen rapidly but smoothly - I'm trying to imitate player movement this is for an 'ai' - as much as I hate to use the phrase.
I've tried running it once and every fixed update while condition met.
Thanks btw - fell asleep on ya'
Answer by JeffHardddyyy · Nov 13, 2016 at 03:01 AM
Couple of things, Just know I am not master of Stuff like this. I'm only like 2 weeks old to Unity
But I do believe that GameObjects can't use .transform.rotation
Because isnt it public transform Object or public GameObject Object
BUUUUUUT Don't give up quite yet, In all of my codes that have to do with Rotation (Thanks Brackeys)
I didn't use transform.rotation as you did in Line 5, I used transform.rotate, So try this
public void TurnAround()
{
transform.Rotate (new Vector3 (x, y, z) * Time.deltaTime);
// Change the x y or z to you're desired way.
// Hope this helps!
}
.
Hehe, I'm not much for giving up.
So, here's the thing. Rotation works, it works pretty well in combination with delta time. The reason I require the use of S/lerp is because this still at times creates what you might call rapid movements or jagged movement when rotating and when working on a first person experience such movement really reduces the experience quality. So slerping essentially takes this rotation and breaks it up into even segments and then iterates through those.
Honestly, I'm having no problem slerping in general, it's how the player rotates the camera with the mouse. The methodology is so similar I don't understand why it's not working atm. Once I get my repo updated I'll post the working code.
I understood none of that, Anyway you can explain so a autistic person would understand haha I'm sorry. I can kinda make up what you're saying.
Basically lerping smooths out the rotation, providing a better first-person experience.