Hello!
The code below should move the character to the right and up. But the movement is being opposite. I already checked the objects orientation, in Unity, but I couldn’t resolve it. If I negate the two components of Vector3 - below - I can correct the movement, but that’s not how the instructor taught. Can someone help me please?
Move(new Vector3(-4, 0, -4));
public class Unit : MonoBehaviour
{
private Vector3 targetPosition;
[SerializeField] private float moveSpeed = 4f;
private void Update()
{
Vector3 moveDirection = (transform.position - targetPosition).normalized;
transform.position += moveDirection * moveSpeed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.T))
{
Move(new Vector3(4, 0, 4));
}
}
private void Move(Vector3 targetPosition)
{
this.targetPosition = targetPosition;
}
}