Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy direction going crazy after collision

$
0
0
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

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>