So I have this problem it started to occur once I added in a model from blender which normally has the x rotation value at -90 degrees at standard and even when I change that in Unity and Blender (re-import etc.) This error would never be fixed, with anything I try. After a while, I noticed the Rotation would only change after the Enemy Chase would start to be active (The enemy saw the player) and then it would become strange.
Before Enemy Chase starts (How it should be)
![alt text][1]
After Enemy Chase Active (How it should not be)
![alt text][2]
I even froze the rotation on all axes and that didn't fix it!
(This is the Code from Enemy Chase )
public class EnemyChase : MonoBehaviour {
public float distanceToPlayer;
public Transform player;
public Animator anim;
public float rotationSpeed = 2f;
void Start ()
{
anim = GetComponent();
this.player = GameObject.FindWithTag("Player").transform;
}
void Update ()
{
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction, this.transform.forward);
if (Vector3.Distance(player.position, this.transform.position) < 20 && angle < 360)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
anim.SetBool("IsIdle", false);
if(direction.magnitude > distanceToPlayer)
{
this.transform.Translate(0, 0, 0.16f);
// The rest is all Animation Stuff so the end doesn't matter!
// With or Without Animation the problem would still occur.
Thanks for the Help!
[1]: /storage/temp/94310-screenshot-3.png
[2]: /storage/temp/94311-screenshot-2.png
↧