Rotate object from localRotation A to localRotation B at rate C.

Afternoon all!

This should be simple, yet I seem to be struggling with it. Scenario is I have a capsule character, a child RotationPivot empty inside him, and a WeaponPoint (child of RotationPivot) outside him.

All I want to do, is if(Input.GetKeyDown(“mouse 0”)), smoothly rotate RotationPivot from local (0,0,0) to local (0,-180,0) at a variable speed, and stop. Doing so would be simple script-based swing of the WeaponPoint across the front of the Capsule. Like I said, should be simple. :stuck_out_tongue:

I’ve looked at Quaternion.RotateTowards and Vector3.RotateTowards, and seem to be having trouble getting them to work right. (Put simply, they’re not moving anything at all.) Is there a better function to use for this, or am I simply inept? lol

Quaternion.Lerp looks like a good candidate, so I’m testing that now.

You should always post a detailed answer when you find one, in case other people have the same question and should not suffer all over again to find a proper solution. So, in case anyone else wonder how did you use Quaternion.Lerp to achieve what was asked in the OP, I send here an example I am currently employing:

 //targetedlocalRotation should be a Quaternion:
 go.transform.localRotation = Quaternion.Lerp(go.transform.localRotation, targetedolcaolRotation,speed);

Apologies for the vague answer. It was a year ago when I was brand new to scripting. ^_^;
I’ve pulled up the full script I used after I got it working, and I can confidently say that I would do it all differently. My code was just… bad. So I won’t confuse the subject by posting it all here. BUT! Here’s the important part that made the pivot rotate:

function SwingWeapon()
{
		swingEnd = Quaternion.Euler(0,180,0);
		swingDuration = 0.35;
        		while(swingDuration > 0)
        		{
        			swingDuration -= Time.deltaTime;
        			swingPivot.localRotation = Quaternion.Lerp(swingPivot.localRotation, swingEnd, swingSpeed);
        			yield;
        		}
}

Using other helper functions to receive click input and call this function, the above made the pivot (a variable of type transform, assigned in the inspector to the empty transform mentioned in the original post) rotate from it’s current rotation to the specified end rotation.

You’ll want to look up Lerp and Quaternion.Euler, but it’s my understanding the the mechanic I was working towards is usually handled by rigging and animation. This was a very rough workaround to make a simple character swing a weapon horizontally in front of it 180 degrees.