Hey guys,
I’m quite new to Unity and game engines.
I’ve created a script which opens a doubledoor depending on which direction the player is coming from,
opening the doors in an appropriate way. (Always opens up to the other side, so it doesn’t smack into players faces)
Everything is working as intended. But I came across a problem.
When I try to rotate the WHOLE doubledoor object to align it to a wall it bugs out.
The hinges are at the right position, they rotated with their parent.
But the door body still faces 0 degrees, even tho I rotated the whole parent.
The door opens up to 90° in world space and closes back to 0° in world space instead of opening to 90° relying on the rotation of it’s parent and closing to 0° relying on the rotation of it’s parent in world space.
Kinda hard to explain for me since I’m quite new to it and my english isn’t the best, but I hope you get what I’m trying to say.
Here’s the script of the action which leads to opening the door.
var AngleX : float = 0.0;
static var AngleY : float = -90.0;
var AngleZ : float = 0.0;
private var targetValue : float = 0.0;
private var currentValue : float = 0.0;
private var easing : float = 0.225;
var Target : GameObject;
function Update ()
{
currentValue = currentValue + (targetValue - currentValue) * easing;
Target.transform.rotation = Quaternion.identity;
Target.transform.Rotate(0, currentValue, 0);
}
function OnTriggerEnter (other : Collider)
{
targetValue = AngleY;
currentValue = 0;
}
function OnTriggerExit (other : Collider)
{
currentValue = AngleY;
targetValue = 0.0;
}
I tried to solve this problem, but I didn’t get a good result. I guess “Target.transform.rotation = Quaternion.identity;” is the root of the problem?
