я создаю 2д игру Unity вид сверху и у меня случился баг : персонаж бесконечно поворачивается как это исправить? вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moving : MonoBehaviour
{
public float speed;
private float moveInput;
public Joystick joystick;
private Rigidbody2D rb;
bool facingRight = true;
public bool moveright;
public bool moveleft;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
moveInput = joystick.Vertical;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
moveInput = joystick.Horizontal;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.x);
}
private void Update()
{
float move = Input.GetAxisRaw("Horizontal");
if (move < 0 && facingRight)
{
flip();
}
else if (move > 0 && !facingRight) ;
{
flip();
}
void flip()
{
facingRight = !facingRight;
transform.Rotate(0f, 180f, 0f);
}
}
}
Ответы (1 шт):
Автор решения: roman lvov
→ Ссылка
you have a flip method right in the Update method, and you want to trigger when the character walks left or right. Take the Flip method out of Update.