Unity 2D Вид зверху + обертання на 90

2075 / Unity / 2D / Гравець / Вид зверху + обертання на 90

 

PlayerRotate902D
  • Rigidbody2D: Gravity Scale 0, Freez Rotation z
  • Всередину героя додаємо img (дивиться вправо)

 

public float moveSpeed = 5.0f;
public GameObject img;
Rigidbody2D rb;
Vector2 movement;

void Start()
{
  rb = GetComponent<Rigidbody2D>();
}

void Update()
{
  movement.x = Input.GetAxisRaw("Horizontal");
  movement.y = Input.GetAxisRaw("Vertical");
}

void FixedUpdate()
{
  if (movement.y > 0)
  {
    img.transform.rotation = Quaternion.Euler(0, 0, 90);
  }
  else if (movement.y < 0)
  {
    img.transform.rotation = Quaternion.Euler(0, 0, -90);
  }
  else if (movement.x > 0)
  {
    img.transform.rotation = Quaternion.Euler(0, 0, 0);
  }
  else if (movement.x < 0)
  {
    img.transform.rotation = Quaternion.Euler(0, 0, 180);
  }
  rb.MovePosition(rb.position + movement * moveSpeed * 0.02f);
}