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

Why is the DesiredAngle not being set?

Asked by 3 years ago

To start off, I am still pretty new to scripting and I am editing a plane kit to have animated landing gears. The landing gear uses Motor6d. When you press G the DesiredAngle of the motor should be changed to what I have written, but the DesiredAngle doesn't change. There is no error in the output section and nothing in the plane kit itself is breaking. Can anyone help me figure out whats going on with the code setting the DesiredAngle?

Here was the code for the gear before I changed it:

Events.GearEvent.OnServerEvent:connect(function(client, val)
    if val == "In" then
        for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do
            if g:IsA("BasePart") then
                g.Transparency = 1
                g.CanCollide = false
            end
        end
        for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do
            if g:IsA("BasePart") then
                g.Transparency = 0
                g.CanCollide = true
            end
        end
    elseif val == "Out" then
        for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do
            if g:IsA("BasePart") then
                g.Transparency = 0
                g.CanCollide = true
            end
        end
        for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do
            if g:IsA("BasePart") then
                g.Transparency = 1
                g.CanCollide = false
            end
        end
    end
end)

And here is the code after I edited it:

Events.GearEvent.OnServerEvent:connect(function(client, val)
    if val == "In" then print("2")
        for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do 
            if g.Name == "Motor" then 
                g.DesiredAngle = 0 do 
            end

            for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do 
                if g.Name == "Motor" then 
                    g.DesiredAngle = -.5  
                end
            end
        end 

    else
        if val == "Out" then print("9")
            for _,g in pairs(Misc.LandingGear.Open:GetDescendants()) do 
                if g.Name == "Motor" then 
                    g.DesiredAngle = 0 
                end
            end
            for _,g in pairs(Misc.LandingGear.Closed:GetDescendants()) do 
                if g.Name == "Motor" then 
                    g.DesiredAngle = -.5 )
                end
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

You need to know that the DesiredAngle property is in radians. You can easily convert degrees to radians by using math.rad(degrees). Also, make sure you have correctly set the MaxVelocity property because setting it to 0 will make the gear snap into place. MaxVelocity is in radians per frame (Roblox has 60 physics frames per second, so 30 frames are 0.5 seconds). Motor6D rotates on the Z-axis of the pivot point when using DesiredAngle, so make sure you configured them correctly as well. An incorrectly configured pivot point may result in your landing gear turning the wrong way.

I hope this answer helps.

0
So converting the degrees to radians will fix the DesiredAngle being set? Or is there something going in with the code that’s causing it to not be set because when I click G the DesiredAngle isn’t set but if I manually type the DesiredAngle it works. GIennMiller 5 — 3y
Ad

Answer this question