- Home /
Question by
RurouniKen · Jul 31, 2019 at 02:46 PM ·
c#joystickrotatearound2d rotation
Object Rotation around another object with right stick
First of all, thanks to anybody that takes its time to read my post.
I want to achieve the same function that the TransforRotateAround does(make an object rotate around other) but with the right stick input of a generic PS4 controller (Hori Pad Fps Plus).
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
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to multi touch on mobile game 1 Answer
move the object where camera look 0 Answers
I'm attempting to make a character face the joystick in a top down unity2d game. 1 Answer