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);
}
asked
Jan 09 '11 at 06:32 PM
Christopher Ellis
2
●
3
●
3
●
3
I have just found out that this method of movement means that it ignores collisions. So I need to add...