- Home /
Question by
Ninth_Perspective · Jun 30, 2020 at 10:56 PM ·
2drotationunity 2drotate object2d rotation
(2D) rotate object to face movement direction
Hello everyone. I am making a 2D game. The movement script is below, and works by:
1.)clicking on the object to select it, and
2.) selecting an end destination.
public class ClickControl : MonoBehaviour
{
static private Transform trSelect = null;
public bool selected = false;
public float speed = 1.5f;
private Vector3 target;
public float soldierRotation = 0f;
void Start()
{
target = transform.position;
}
void Update()
{
if (selected && transform != trSelect)
{
selected = false;
}
if (Input.GetMouseButtonDown(0) & selected == true)
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
//This will be used for rotation.
transform.Rotate(0, 0, soldierRotation);
//DOES NOT WORK. EFFECTS: NONE, OR OFF-SCALE.
}
transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
public void OnMouseDown()
{
selected = true;
trSelect = transform;
}
}
//UPDATE 06/28/2020 FUNCTIONS AS INTENDED. USE THIS INSTEAD.
I want to rotate the characters toward the end destination, so that the centre line of the player is aligned with the line between the starting point of the player and the destination. Thanks in advance, Me
Comment
Answer by Ninth_Perspective · Jul 02, 2020 at 03:49 PM
Test Answer. PS I cannot see any answers, if there are any.