Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

make enemy only follow along the X and Z axis

$
0
0
currently I have this script which makes my enemy move towards me and attack me when he in a surtain distance away from the player but when He gets that close first he stards to rotate like he is looking up to me and when I jump he even rotates like he is lying on the ground just to follow the player and I dont want that I only want the enemy to follow the player and rotate towards his X and Z axis var Target : Transform; var Speed : float; var Hit = 1; var HitDelay = 1; function Update () { var distance = Vector3.Distance(gameObject.transform.position, Target.transform.position); if(distance > 2) { GetComponent.().Play("walk"); var Step = Speed * Time.deltaTime; var relativePos = Target.position - transform.position; var rotation = Quaternion.LookRotation(relativePos); transform.rotation = rotation; transform.position = Vector3.MoveTowards(transform.position, Target.position, Step); } else if(distance < 2) { Attack(); } } function Attack() { GetComponent.().Play("attack"); yield WaitForSeconds(HitDelay); Target.transform.SendMessage("PlayerHitted", Hit, SendMessageOptions.DontRequireReceiver); } I know that there is nothing like something.position.x/y/z when using vector3.MoveTowards and the rotation thing I used doesn't work either because it's the MoveTowards that makes him rotate the strange way it does I hope someone can help me thanks

Viewing all articles
Browse latest Browse all 536

Trending Articles



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