- Home /
Question by
Creative Inventory · Aug 07, 2015 at 04:12 PM ·
rotationdirection
How do I make my player face the direction its moving.
Okay I'm making an android game for fun, and I added a GoToMouse script (below) to my character, so my character follow where I click (or tap on my phone). But when I click to the left or right my character does face the direction it's moving, please can some one help!!! Thank you!!!
using UnityEngine;
using System.Collections;
public class GotoMouse : MonoBehaviour {
public float speed = 1.5f;
private Vector3 target;
void Start () {
target = transform.position;
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycasting from object rotation? 1 Answer
Getting the face direction 2 Answers
Rotation to go from one direction to another? 0 Answers
Rotation of character resets when joystick is released 3 Answers
How to make an object go the direction it is facing? 6 Answers