Page 1 of 1
A Script to lock the rotation of a layer
Posted: Sat Jan 22, 2022 12:13 pm
by bbrraayyaann
Hi, I am very inexperienced writing script in Lua.
And well I was trying to create an embedded script.
Something that is immune to the parent of the layer and when rotated does not affect the child.
If anyone can help me or there is a way please.
I leave you the script:
Code: Select all
function LayerScript(moho)
local layer = moho.document:LayerByAbsoluteID(1)
layer.fRotationX:SetValue(moho.frame,true)
layer.fRotationY:SetValue(moho.frame,true)
layer.fRotationZ:SetValue(moho.frame,true)
end
Also the files.
I embedded the script in the Child layer. :
https://www.mediafire.com/file/7ah01xo8 ... e.rar/file
Re: A Script to lock the rotation of a layer
Posted: Sat Jan 22, 2022 8:43 pm
by synthsin75
First, for a layerscript, moho.layer is the layer the script is embedded on. So no need to find it with LayerByAbsoluteID.
Second, layer rotation is a number value, so trying to set it to "true" (a boolean) is meaningless.
You also don't generally want a layerscript to SetValue (keyframe), when you can just set the current .value.
You could try setting the layer's (moho.layer) rotations to the opposite of the parent layer's:
layer.fRotationX.value = layer:Parent().fRotationX.value * -1
But that only works up to a certain point. It may require dealing with the transform matrix, but that's not something I'd suggest a new scripter try.
Re: A Script to lock the rotation of a layer
Posted: Sat Jan 22, 2022 9:54 pm
by bbrraayyaann
synthsin75 wrote: ↑Sat Jan 22, 2022 8:43 pm
First, for a layerscript, moho.layer is the layer the script is embedded on. So no need to find it with LayerByAbsoluteID.
Second, layer rotation is a number value, so trying to set it to "true" (a boolean) is meaningless.
You also don't generally want a layerscript to SetValue (keyframe), when you can just set the current .value.
You could try setting the layer's (moho.layer) rotations to the opposite of the parent layer's:
layer.fRotationX.value = layer:Parent().fRotationX.value * -1
But that only works up to a certain point. It may require dealing with the transform matrix, but that's not something I'd suggest a new scripter try.
Hi, thanks for the answer Synthsin75:
What I want is more than anything that the layer always looks at the camera.
I have tried with the pivot on the x,y axis and pivot freely, but always when I try to rotate on the x,y axis - at the same time everything is deformed.
Re: A Script to lock the rotation of a layer
Posted: Sat Jan 22, 2022 10:17 pm
by synthsin75
It might help to have some idea of what you're trying to achieve.
Does the face camera layer have to be in the group layer, or just translate with the group (without scaling or rotating)?
Re: A Script to lock the rotation of a layer
Posted: Sat Jan 22, 2022 11:18 pm
by bbrraayyaann
synthsin75 wrote: ↑Sat Jan 22, 2022 10:17 pm
It might help to have some idea of what you're trying to achieve.
Does the face camera layer have to be in the group layer, or just translate with the group (without scaling or rotating)?
For example:
I create a group, and inside the group there is a layer that would come to be the child.
The child must always look at the camera (on the x, y, z axis).
The parent can rotate on the axes (x, y, z), but the child would be immune. It must be still.
This only applies to the child (which would have the embedded script), any parent is free to rotate.
Re: A Script to lock the rotation of a layer
Posted: Sun Jan 23, 2022 12:01 am
by synthsin75
Oh, I get that much. I just don't understand how you intend to use this in an animation. If I knew the end goal, there may be other ways to accomplish the same thing.
I just don't understand why you need a child layer to ignore it's parent layer transforms, as a parent layer is usually used when you do need its transforms.
EDIT: Here's an example of a vector layer being moved by a group layer, but the group layer's rotation and scale do not affect the vector layer:
https://www.mediafire.com/file/szkh7i5j ... .moho/file
The vector layer isn't in the group layer, but it's set to follow a path in the group layer.
Re: A Script to lock the rotation of a layer
Posted: Sun Jan 23, 2022 12:54 am
by bbrraayyaann
synthsin75 wrote: ↑Sun Jan 23, 2022 12:01 am
Oh, I get that much. I just don't understand how you intend to use this in an animation. If I knew the end goal, there may be other ways to accomplish the same thing.
I just don't understand why you need a child layer to ignore it's parent layer transforms, as a parent layer is usually used when you do need its transforms.
EDIT: Here's an example of a vector layer being moved by a group layer, but the group layer's rotation and scale do not affect the vector layer:
https://www.mediafire.com/file/szkh7i5j ... .moho/file
The vector layer isn't in the group layer, but it's set to follow a path in the group layer.
Oh, thank you very much Synthsin75 .
I didn't know it could be done that way. It worked for me
Re: A Script to lock the rotation of a layer
Posted: Sun Jan 23, 2022 1:15 am
by synthsin75
bbrraayyaann wrote: ↑Sun Jan 23, 2022 12:54 am
Oh, thank you very much Synthsin75 .
I didn't know it could be done that way. It worked for me
That's great, man. I had no idea if you needed the layer inside the group or not. Glad it worked fro you.
