- Home /
Maximum speed mouse follow without rotation
Hi, I'm just starting out and I'm trying to get a character to follow the mouse which I've seen a lot of help for. My problem is that I need the character not to rotate toward the mouse, they need to just move to it. I also want to cap the speed that they can follow the mouse. Smooth follow was the closest I came so far, but it slows me down too much as I approach the mouse.
So to recap my main goals are:
- Follow the mouse
- Don't rotate
- Move at a constant speed
- Don't go faster than a maximum speed
Here's the closest I have so far... most of this was put together from other answers on this site:
var target : Transform; var smoothTime = 0.3;
private var thisTransform : Transform;
function Start() { thisTransform = transform; }
function Update () {
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
}
thisTransform.position.x = Mathf.Lerp( thisTransform.position.x, targetPoint.x, Time.deltaTime * smoothTime);
Debug.Log(thisTransform.position.x);
thisTransform.position.z = Mathf.Lerp( thisTransform.position.z, targetPoint.z, Time.deltaTime * smoothTime);
Debug.Log(thisTransform.position.z);
}
I have just found out that this method of movement means that it ignores collisions. So I need to add...
$$anonymous$$ust allow the object to react properly to collisions (ex. Don't move through a wall)
Your answer
Follow this Question
Related Questions
rotate camera on mouse reaching edges 1 Answer
Mouse move with specific speed? 2 Answers
Different speed on different phones 0 Answers