Quantcast
Viewing all articles
Browse latest Browse all 1488

Character continues moving when locked onto an enemy

Ok so here's my issue, I have a script that allows me to lock on to and orbit an enemy target. The problem is if my character is moving when pressing the lock on button the character will continue moving in whatever direction it was going before the button was pressed regardless of any more button presses save for the opposite direction. This doesn't happen when I'm stationary, if my character stands still and I press the lock on button everything works fine. It's only when I'm moving. I'm not sure if this is enough information, or what else someone might need to better understand but here is my script. if (GetComponent().locked)//checks bool to see if lockOn button was pressed { mainCam.SetActive(false);//turns off main cam lockCam.SetActive(true);//turns on lockOn cam movesetting.tarObject = GetComponent().Closest;//target object will be the closest enemy to player this.transform.LookAt(movesetting.tarObject.transform.position);//player will look at the target object at all times if (currXRot.x > maxXRot.x)//if the current x rot of this object exceeds the maxXRot it can go... currXRot.x = maxXRot.x;//it gets reset transform.Translate(Vector3.right * movesetting.speed * Time.deltaTime * turnInput);//orbits around the target object transform.Translate(Vector3.forward * movesetting.speed * Time.deltaTime * forwardInput);//in control of moving towards and away from target } Any and all help is greatly appreaciated, thank you in advance. If you need more info or if something isn't clear please let me know.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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