- Home /
cant freeze rotation or set it manually to 0 on Zombie Model, Freezing or setting rotation not working
I have a Zombie Model, where i have a Rigidbody attached and that Moves Towards me and Attacks me. But it rotates around the frozen X axis and even if i set it in the script with every possible answer, it doesnt work
public void FixedUpdate()
{
transform.Rotate(0, transform.rotation.y, transform.rotation.z, Space.World);
}
// Update is called once per frame
void Update()
{
DistanceToPlayer = Vector3.Distance(transform.position,player.position);
if(DistanceToPlayer < safeDistance)
{
transform.LookAt(player.position);
transform.Translate(new Vector3(0, 0, 0));
if (canAttack == false) return;
ZombieAnimator.Play("Attack");
Invoke("Attack", 2.0f);
canAttack = false;
if(Health.playerarmor > 0)
{
Health.playerarmor -= 10;
}
else
{
Health.playerHealth -= 15;
}
}
if(DistanceToPlayer > safeDistance)
{
transform.position = Vector3.MoveTowards(transform.position, player.position, movementspeed * Time.deltaTime);
transform.LookAt(player.position);
ZombieAnimator.Play("Walk");
}
}
void Attack()
{
canAttack = true;
}
Comment
Answer by KoenigX3 · May 25, 2020 at 07:36 PM
By putting that line into FixedUpdate:
transform.Rotate(0, transform.rotation.y, transform.rotation.z, Space.World);
It won't stop the transform from rotating around the X axis. Setting Rigidbody.constraints to RigidbodyConstraints.FreezeRotationX will do that.
Your answer
Follow this Question
Related Questions
Model stays at the end of my animation D:? 0 Answers
Model freaks out when animating 0 Answers
Position of GameObject changes when animating 2 Answers