Question by
RurouniKen · Jul 30, 2019 at 06:25 PM ·
c#movementinputrotatearound2d rotation
How to Transform.Rotate Around with the rotation of the controller right stick
First of all, thanks to anybody that takes its time to read my post.
I need help to make an object rotate around other by rotating the right stick of the controller.
I have this code so far that will rotate around the other object automatically.`public class CoreOrbitMovement : MonoBehaviour
{ private Rigidbody2D myRigidBody; public float rotateSpeed;
private Vector3 zAxis = new Vector3(0,0,1);
public Transform target;
// Start is called before the first frame update
void Start()
{
myRigidBody= GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{ //Access the z azis on noth vertical and horizontal movement of the right jostick
float h = Input.GetAxisRaw("RightStickHorizontal");
float v = Input.GetAxisRaw("LeftStickVertical");
RotateChar() ;
}
public void RotateChar() {
zAxis.Normalize();
transform.RotateAround(target.position, zAxis,rotateSpeed);
}
}`
Comment