- Home /
Moving my object toward a position even though it's not facing that position.
So I tried messing around with the AI.js from the FPS tutorial, since I want to move my robot while it is shooting me. After several hours looking around, I found out the reason I couldn't do that was because it rotates the robot to move, and in order to shoot it rotates the robot. So basically the robot just fires straight ahead all the time. So this means... I cant modify it for my purpose. But I was thinking maybe I could change the way it moves, so when it rotates toward me. I could somehow manage to move it sideways?
So I have these code:
// Rotate towards the target transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime); transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);
// Modify speed so we slow down when we are not facing the target var forward = transform.TransformDirection(Vector3.forward); var speedModifier = Vector3.Dot(forward, direction.normalized); speedModifier = Mathf.Clamp01(speedModifier);
// Move the character direction = forward speed speedModifier; GetComponent (CharacterController).SimpleMove(direction);
Where the forward probably means it will move forward all the time. So I was thinking maybe I can use some calculation to make this forward to another variable, so my robot always points to my waypoint position?
Maybe this is a bad way to do it, or maybe someone got a better solution?
Thanks in advance.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085014im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you make a ragdoll blow apart? 1 Answer
How do I make a FPS Boss? 1 Answer
How do you make a enemy AI hear approaching footsteps? 2 Answers
Making bullet holes in enemies. 1 Answer
FPS TUTORIAL HELP 1 Answer