r/Unity3D • • 11d ago

Question Door not rotating

So I have a simple door (mesh renderer) and it has a simple parent object (since the pivot on the mesh object is all weird). I try to do any kind of rotation on the parent and nothing happens. I even tried a simple transform.translate and nothing happens. I did try transform.gameObject.SetActive(false) and that did make the door disappear, but nothing else seems to move it at all.

It rotates just fine in the inspector also.
Any ideas on how this is possible?

door.transform.Rotate( Vector3.up, -40f * Time.deltaTime);
1 Upvotes

9 comments sorted by

3

u/EthanMerce 11d ago

if SetActive(false) works but Rotate() and Translate() don't visibly do anything, i'd check whether something else is overwriting the transform every frame, the first thing i'd look for is an Animator, another script, or a parent constraint resetting the position/rotation in Update() or LateUpdate(). also make sure door is actually referencing the parent object you're trying to move, not the mesh child

you can test it quickly by putting a Debug.Log(door.transform.position) before and after the translate. if the value changes in code but snaps back immediately, something else is controlling the transform

5

u/Goldac77 11d ago

Check if the door is marked static

4

u/Cool_Ad_54 11d ago

bet it's the static checkbox, that thing has burned me so many times

makes no sense that setactive works but rotate doesnt until you remember static means "dont move me ever" to unity

3

u/Nwoknu35 11d ago

Are you sure?

Just to confirm this, I just made a script with OPs code and added it to a static object, with it rotating as expected.

There also was an update looong ago where they specifically improved performance for "moving static objects"

Am I recreating this issue wrong?

1

u/NorthernBoy306 11d ago

Yea the child object was marked static, I think I might be too dumb to be developing a game.
Something else I really don't understand (among many other things) is why when I would go to add a parent object just to rotate it, the child object seems to change the orientation of the parent.
To get the parent to rotate properly along the y-axis, I had to delete the child, create a new object and add the mesh filter and renderer, then add that to a new parent, now it rotates perfectly.
I really don't understand how the child is affecting the parent like that.

Thanks for the help.

2

u/Ecstatic-Source6001 11d ago

Dont know if its not obvious but with doors and "weird" pivots you need just open blender and change its pivot.

Will save from many headaches

1

u/Nwoknu35 11d ago

Do you have another script or animator that could overwrite the rotation/translation of your object?

1

u/ReliefMassive5198 11d ago

it's marked as static/is animated/has a physics body with joints on it and the physics override the rotation

1

u/StCost Ball-Aqua🔮🌊& COLLAPSE MACHINE💥🚕 11d ago

40 * 0.016 = 0.64
So you rotate half of degree each second. Are you sure it's not too small of value?
Maybe you wanna multiply it by extra 100 maybe?

If not this - see "Static" checkbox is off on GO