I’m currently trying to make a game where the character follows the mouse pointer. but I want the character to lag behind the mouse a little bit (a set speed). I also don’t want this character to travel in the X Direction. that way it doesn’t travel forward. here’s my code so far :
using UnityEngine;
using System.Collections;
public class ShipControl : MonoBehaviour
{
public float distance = 1.0f;
public bool useInitalCameraDistance;
private float actualDistance;
// Use this for initialization
void Start () {
if (useInitalCameraDistance) {
Vector3 toObjectVector = transform.position - Camera.main.transform.position;
Vector3 linearDistanceVector = Vector3.Project(toObjectVector,Camera.main.transform.up);
actualDistance = linearDistanceVector.magnitude;
}
else
{
actualDistance = distance;
}
}
void Update ()
{
Vector3 mousePosition = Input.mousePosition;
mousePosition.z = actualDistance;
transform.position = Camera.main.ScreenToWorldPoint(mousePosition);
}
}
It works except the stuff I mentioned above. Any tips? (this is a flying object, so Up, Down, Left, Right are need. but not Forward or backwards)