- Home /
Rigidbody to follow player around
Hi all,
I currently have a group of rigidbodies (my enemies) looking at the player as he moves. I need to go a step further and have them transform forward toward the player upon him moving. This is currently what I have for the enemy looking at the player:
public class EnemyLook : MonoBehaviour {
public Transform target;
void Update () {
transform.LookAt(target);
}
}
This is my script for player movement:
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Mouse X");
float moveVertical = Input.GetAxis ("Mouse Y");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
I'm still getting to grips with C# and Unity so any help will be greatly appreaciated.
Thanks
Comment
Best Answer
Answer by Deathdefy · Oct 29, 2013 at 05:36 PM
This will help get you started ;).
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.MoveTowards.html