Hi, I’m trying to program doors that open slightly when you scroll the mousewheel around, and my door gets rotated on its side?
using UnityEngine;
using System.Collections;
public class BDXDoorScript : MonoBehaviour
{
private float MaxRotation = 90f;
private float MinRotation = -90f;
private float RotateAmount = 20;
public Quaternion DoorRotation;
void Start ()
{
MinRotation = transform.rotation.z - 80f;
MaxRotation = transform.rotation.z + 80f;
DoorRotation = transform.rotation;
}
public void RotatePositive ()
{
print ("Doorscript_RotatePositive");
DoorRotation = transform.rotation;
DoorRotation.z+=RotateAmount;
DoorRotation.z = Mathf.Clamp(DoorRotation.z, MinRotation, MaxRotation);
transform.rotation = DoorRotation;
}
public void RotateNegative ()
{
print ("Doorscript_RotateNegative");
DoorRotation = transform.rotation;
DoorRotation.z-=RotateAmount;
DoorRotation.z = Mathf.Clamp(DoorRotation.z, MinRotation, MaxRotation);
transform.rotation = DoorRotation;
}
}
I’m trying to rotate the door, and clamp it by 90 degrees (Both set to 80 for debugging) both ways, so the door can only swing 180 degrees.
Problem is, upon rotating… The door flips on its side? Is this something with .Blend fbx?