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

Enemies not rotating properly towards the player - Javascript

$
0
0
Recently I was able to fix the implementation of enemies flying/turning towards the player. However, the issue that I'm having with this is that they are rotating and flying at a weird way so that you're unable to see the enemy. I have the Z scale set at 0.1 because I wanted them to be flat images. I'll attach a screenshot of my enemies on the screen. I'll also put up my code that has them moving. How can I get the enemies to stay flat without turning along any Axis that puts them not in view? I'd rather avoid having to increase their scale. I've also attempting to freeze their rotation/position on the X, Y, and Z axis' and nothing seems to hold them flat. var myRigid : Rigidbody ; var myTrans : Transform ; var speed : float = 20f ; var target : Transform ; var forceMode : ForceMode ; private var dir : Vector3; function Start() { target = GameObject.FindWithTag("Player").transform ; myRigid = this.rigidbody ; myTrans = this.transform ; } function Update () { if(gameObject.name == "Enemy_Pink(Clone)") { if(target){ dir = target.position - myRigid.position; dir.Normalize(); myTrans.rotation = Quaternion.Slerp(myTrans.rotation, Quaternion.LookRotation(dir), speed * Time.deltaTime); //myRigid.constraints = RigidbodyConstraints.FreezePosition; } } if(gameObject.name == "Enemy_Blue(Clone)") { if(target){ dir = target.position - myRigid.position; dir.Normalize(); myTrans.rotation = Quaternion.Slerp(myTrans.rotation, Quaternion.LookRotation(dir), speed * Time.deltaTime); //myRigid.constraints = RigidbodyConstraints.FreezePosition; } } if(gameObject.name == "Enemy_Red(Clone)") { if(target){ dir = target.position - myRigid.position; dir.Normalize(); myTrans.rotation = Quaternion.Slerp(myTrans.rotation, Quaternion.LookRotation(dir), speed * Time.deltaTime); //myRigid.constraints = RigidbodyConstraints.FreezePosition; } } } function FixedUpdate() { myRigid.AddForce(myTrans.forward * speed, forceMode); } ![alt text][1] [1]: /storage/temp/24541-24492-screenshot_interruptionsystem.png

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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