Well, this is my first time here friends! I wrote a simple code for moving an enemy. But when he collides with anything he seems to lose direction (following the player).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mouthless_Behaviour : MonoBehaviour
{
public Transform target;
public float rotationSpeed = 0.1f;
public float movementSpeed = 1.0f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (target != null)
{
transform.position += transform.forward * Time.deltaTime * movementSpeed;
var rotation = Quaternion.LookRotation (target.position - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation,
rotation, Time.deltaTime * rotationSpeed);
}
}
}
If he collides with anything he change his direction and stop following the player.
Here a GIF from this issue: [Here!][1]
[1]: https://tenor.com/view/gif-13317762
↧