Hi,
I’ve built a Navigation Mesh and created a NavMesh Agent for an NPC sphere GameObject. In order for the NPC to chase the player, I’ve created this script for the sphere object :
using UnityEngine;
using System.Collections;
public class MoveTo : MonoBehaviour {
public float speed = 5.0F;
GameObject player;
Rigidbody rb;
Vector3 movement;
NavMeshAgent ball;
void Start () {
player = GameObject.Find ("Player");
rb = GetComponent<Rigidbody> ();
ball = GetComponent<NavMeshAgent>();
}
void FixedUpdate() {
Pursuit ();
}
void Pursuit() {
ball.destination = player.transform.position;
transform.LookAt (ball.destination);
rb.AddRelativeForce (Vector3.forward.normalized * speed);
}
}
The ball chases the player, but the problem is that the ball is moving without rolling. I’ve tried to use Rigidbody.MovePosition, but the ball simply teleports to my player (no matter if I enable or disable interpolate in the Inspector for the RigidBody):
void Pursuit() {
rb.MovePosition(transform.position + transform.forward * Time.deltaTime);
}
I would appreciate any hint on how to implement an automatic navigation rolling movement for the ball.
Thanks a lot