Doubledoor Script - Hinge rotates in world space instead of parents rotation

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?

Bump!

Bump!

Check out the documentation for transform.Rotate(…). You need to specify the rotation space.

Thanks for the answer!
So it would be “Target.transform.Rotate(0, currentValue, 0, Space.Self);” to use the degree axis of the parent? (or the local axis of the gameobject, doesn’t matter in my situation)
Cuz that doesn’t work for me I just tried it out, Space.Self and Space.World bring the same results.

Here’s a screenshot of the problem! Scene and InGame view!
1507764--85241--$Unbenannt.jpg

Use Unity - Scripting API: Transform.localRotation

That’s it! It works!
Thanks for your help!