- Home /
Question by
CrabbyLobster · May 31, 2020 at 02:03 PM ·
c#movement2d rotation
Rotate to where the player is moving
Hello, I am making a 2D game and would like the player (a square) to rotate towards the way it's moving. Here is the movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
[Range(1f, 100f)]
public float speed = 1f;
void Update()
{
var move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
transform.position += move * speed * Time.deltaTime;
}
}
Thanks!
Comment
Best Answer
Answer by KoenigX3 · May 31, 2020 at 03:12 PM
You can use Quaternion.LookRotation.
transform.rotation = Quaternion.LookRotation(move);
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Changing the landing and switch directions of standard assets TPC controller 0 Answers
Character Rotation 2 Answers