Hello all!
I’m in a little bit of a pickle, what I’m wanting to do is make my sprite rotate accordingly to the direction it’s heading. Right now, it seems to just rotate on some weird 360 axis and snap inappropriately.
Here’s a video to better describe my problem. I’m trying to make it work like Game Maker orients a sprite with rotation.
Here is my current code for said Unity script.
using UnityEngine;
using System.Collections;
public class PawnPlane : MonoBehaviour {
private Vector3 mousePosition;
private Vector3 mouseRotation;
public float moveSpeed = 1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// if (Input.GetMouseButton(1))
{
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position += new Vector3(mousePosition.x,mousePosition.y,0) * 1.0f * Time.deltaTime;
Vector3 moveDirection = gameObject.transform.position;
float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}
}
Any help would greatly be appreciated!
Thanks