right, is there a way to have a lookAt script that will only use 2 dimensions? My problem is that when I get to close to my character the character "bends"away from me
http://forum.unity3d.com/threads/91036-Need-Alternative-AI-Script
Take a look at the above thread. User was having a similar problem and the easy fix is to add a small snippet where you do your rotation to clamp it so that only the axis you want them to rotate on are affected.
thanks! However I’m confused about the direction variable
tried modifying it like so:
however that didn’t do anything.
I’m unsure of what functions you’re using to rotate your NPC in your script since you did not post a code snippet. There are different ways to prevent the type of issue you’re having, depending on what manner you chose to rotate the NPC. In the formerly posted thread the part that fixed his particular issue was the:
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), 2* Time.deltaTime);
[B]transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);[/B]
if you’re going to try and make use of the above snippet you’re probably going to have to make some changes to the rest of your script to match what the above was designed for.
You might be able to do a search for clamping rotation angles as well for further help on different ways to do this.
Got it to work! don’t know why it didn’t before gosh I’m so stupid. I just used
and combined it with the simple constraint script (found it a while back on these forums) where I checked “constrain rotation x” - sorry for all the trouble but yay it works!
Thank you for posting your fix as well