Reputation: 1091
I would like to implement the type of behavior where a group of prey is evading from a predator like this Game
I tried to write the script this way but I don't get the desired motion the prey just moves forward.
public Transform target;
public float damping;
public float drivespeed;
void Update () {
transform.Translate(Vector3.forward * Time.deltaTime * -drivespeed);
Quaternion rotation = Quaternion
.LookRotation(target.position - transform.position);
transform.rotation = Quaternion
.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
Upvotes: 0
Views: 44
Reputation: 169184
Looks like you want
transform.Translate(transform.forward * Time.deltaTime * -drivespeed);
instead of
transform.Translate(Vector3.forward * Time.deltaTime * -drivespeed);
(Vector3.forward
being a world forward vector, not the object's forward vector.)
Upvotes: 2
Reputation: 113
It could be that the transform.translate is being called before the rotation logic but it's hard to tell what's going wrong here.
Upvotes: 0