I have tried to control my object with my mouse using this code:
using UnityEngine;
using System.Collections;
public class AstronautScript : MonoBehaviour {
public float SPEED; //In units per frame
Vector3 destination;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire2")) {
Vector3 pos = Input.mousePosition;
pos.z = 0;
destination = Camera.main.ScreenToWorldPoint(pos);
}
}
void FixedUpdate () {
Vector3 movement = destination - transform.position;
GetComponent<Rigidbody2D>().velocity = movement.normalized*SPEED;
}
}
As you can see I’ve normalized the movement vector, but when I play my game, the speed of the object is higher the farther away from the destination that it is. Anyone have an answer?