- Home /
Rotate using pivot point
I'm using the following code for rotate my surface controls:
using UnityEngine;
using System.Collections;
public class pivotTest : MonoBehaviour {
Transform C_elevator;
// Use this for initialization
void Start ()
{
C_elevator = transform.FindChild("C_elevator");
}
void Update ()
{
float vertical = Input.GetAxis("Vertical") * Time.deltaTime * 10;
C_elevator.RotateAround(C_elevator.position, C_elevator.right, vertical);
}
}
The problem is while I'm not changing my axis, surfaces should return to the idle position. I assume I should change my object's rotation...
Can you help me, please?
You don't give enough information for anyone to help you. You could add a script like this to one of the objects to continuously rotate it:
function Update() {
transform.Rotate(0.0, 90.0 * Time.deltaTime, 0.0);
}
But I suspect you want something to control the rotation so they act like plane control surfaces.
Answer by robertbu · Jun 03, 2013 at 02:59 PM
Assuming that a rotation of (0,0,0) puts the elevator back into position, you can do the following (untested):
void Update ()
{
float vertical = Input.GetAxis("Vertical") * Time.deltaTime * 10;
if (vertical > 0.01f)
C_elevator.RotateAround(C_elevator.position, C_elevator.right, vertical);
else
C-elevator.localRotation = Quaternion.Slerp(C-elevator.localRotation, Quaternion.identity, Time.deltaTime * return_speed);
}
'return_speed' is a variable you define that controls how fast the elevator will return. You can replace Quaternion.Slerp() with Quaternion.RotateTowards() if you don't want easing at the end of the movement.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103251im_/https://answers.unity.com/themes/thub/images/avi.jpg)