-3
Hello! I’m testing a 2D, platform-style drive. Basically, I want when the player presses "A," it rotates to the right. I managed to do it, but I want him to turn around, not just out of nowhere he already turns right....
[Header("Main")]
public int Speed;
[Header("Inputs")]
float HorizontalInput;
[Header("Others")]
Rigidbody2D Rig;
// Start is called before the first frame update
void Start()
{
Rig = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Move();
Rotate();
}
void Move()
{
HorizontalInput = Input.GetAxis("Horizontal");
Rig.velocity = new Vector2(HorizontalInput * Speed, Rig.velocity.y);
}
void Rotate()
{
if(HorizontalInput > 0)
{
transform.rotation = Quaternion.Euler(0, HorizontalInput * 0, 0);
}
if(HorizontalInput < 0)
{
transform.rotation = Quaternion.Euler(0, HorizontalInput * (180 * -1), 0);
}
}
I tried this Script, it is turning to the left normally, but when I turn to the right, it already goes straight... (Try to put this code in Unity to understand better, I tried to put a video but it seems that it is not possible in Stackoverflow.