Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I keep a fixed rotation for a hat on roblox?

Asked by 3 years ago

So I've been trying to recreate the old lighting system roblox has and because I'm lazy the way I've been shading the head is I have a mesh that goes over every face of the head that should be shaded, but obviously the head will move so I've needed to keep the Y orientation at 0.

I've tried a body gyro to keep the Y position the same but for obvious reasons this rotated the entire player. I've also tried a while look to keep it in position, but since there's a slight delay, if the player rotates quickly the effect is lost for a short second.

On top of this, I can't actually make the Y orientation be a constant 0 otherwise when the Y rotation of the head isn't a perfect multiple of 11.25 the head will jet out a bit. I've tried making the mesh a bit bigger but since the player can move their camera, this causes issues with the player being able to see that its actually just a mesh and not real shading at some examples. I've tried to get the difference from the head's orientation and the closest multiple of 11.25 and set the Y orientation of the shading to be that difference, but once again because of the slight delay it doesn't work too well.

This is the code I've been using if that helps:

while wait() do
    local headrot = script.Parent.Parent.Head.Orientation
    if headrot.Y > 11.25 then
        local rot  = headrot.Y-math.floor(headrot.Y/11.25+0.5)*11.25
        script.Parent.Orientation = Vector3.new(headrot.X,0-rot,headrot.Z)

        end
    if headrot.Y < -11.25 then
        local rot  = headrot.Y-math.floor(headrot.Y/11.25+0.5)*11.25
        script.Parent.Orientation = Vector3.new(headrot.X,0+rot,headrot.Z)

    end
end

Answer this question