Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Enemy follow script problem

$
0
0
Hey guys, this might be a really simple question but I just can't seem to figure it out, I have a follow script attached to my "Enemies" and it works, they rotate towards the player and follow him till they are a certain distance away. However, the enemies seem to move along the y axis to match the players height (resulting in the enemies partialy going throught the terrain) so I changed it to follow the main cam which is a first person cam attached to the player (now the enemies are floating above ground to match the cams height) so my question is how do I stop the gameobjects from moving along the y axis? No rigidbodies are attached to enemies just a trigger and a collider. Here's my script; p.s have tried with rigidbodies and constrants, gravity, etc. public Transform player; public float moveSpeed = 5f; public float minDist = 2f; // Use this for initialization void Start () { player = GameObject.FindGameObjectWithTag ("MainCamera").transform; } // Update is called once per frame void Update () { transform.LookAt (player); if (Vector3.Distance (transform.position, player.position) >= minDist) { transform.position += transform.forward * moveSpeed * Time.fixedDeltaTime; } } }

Viewing all articles
Browse latest Browse all 827

Trending Articles



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