I have a model of a man, that looks in players direction, when close. But when the player jumps, he rotates in a weird upwards rotation, where he almost "lies down".
How to prevent him from rotating like that?
Vector3 difference = player.position - transform.position;
difference.y = 0; // Syntax here may be language-dependent
rotate = Quaternion.LookRotation(difference);
Sorry, the syntax for the first line will probably be language-dependent as well. (In other words, you'll need to adapt what I posted based on which scripting language you're using.)
You can try it (and it may work), but note that manipulating the elements of a rotation quaternion directly may not always have the effect you expect. Personally, I'd go with the method I posted (perhaps with a length check to catch the case where the player is more or less directly above or below the agent). But, YMMV.
Sorry, the syntax for the first line will probably be language-dependent as well. (In other words, you'll need to adapt what I posted based on which scripting language you're using.)
– j_y_kHave you tried it? (rotate.y = 0, that is...)
– j_y_kYou can try it (and it may work), but note that manipulating the elements of a rotation quaternion directly may not always have the effect you expect. Personally, I'd go with the method I posted (perhaps with a length check to catch the case where the player is more or less directly above or below the agent). But, YMMV.
– j_y_k