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

Making A Spinning Part Above Character?

Asked by
Pejorem 164
7 years ago

Probably a frequently asked and used question but here it is. I've welded a Part (duck) above the Character's head upon joining. But I'm unaware of how to make it spin? What I've got so far just makes it do something.... weird*?

--PlayerAdded script (ServerScriptService)

function makeDuck(plr)
    local duck = script["Blue Duck"]:clone()
    duck.Parent = plr.Character
    duck.Position = plr.Character.Head.Position + Vector3.new(0, 4, 0)
    duck.Rotation = plr.Character.Head.Rotation
    local weldTo = plr.Character.Head
    local weldToCf = weldTo.CFrame:inverse()
    local weld = Instance.new("Weld")
    weld.Name = "DuckWelding(warning, high temperatures)"
    weld.Part0 = weldTo
    weld.Part1 = duck
    weld.C0 = weldToCf
    weld.C1 = duck.CFrame:inverse()
    weld.Parent = weldTo
    duck.Anchored = false
    duck.CanCollide = false
end

And then after this:

--Script inside duck
local duck = script.Parent

function rotateSomeDuckyThatIUsedToKnow()
    local weldForDuck = duck.Parent:FindFirstChild("Head")["DuckWelding(warning, high temperatures)"]
    while wait() do
        weldForDuck.C0 = duck.CFrame:inverse()*CFrame.fromEulerAnglesXYZ(0, math.pi/180, 0)
    end --This is basically the only line that doesn't do what I want it to
end



duck.AncestryChanged:connect(function(child, parent)
    print("someDuckyThatIUsedToKnow got TRIGGERED!!!!!") wait(5)
    if parent:IsA("Model") then
        rotateSomeDuckyThatIUsedToKnow()
    end
end)

The line inside the while loop in rotateSomeDuckyThatIUsedToKnow() is basically the only part I'm ignorant of what I'm supposed to be doing. Can someone explain what's happening here? According to what I read from the wiki, it should rotate the duck.

*As I wrote this I found one thing I was doing wrong; so weird now means it is kinda moderating its position above the head as if it's some futuristic hoverboard.

0
Spinning as in rotating on axis maintaining position above head. Pejorem 164 — 7y
0
If u want it to spin, why weld the duck to the head? doesn't that stop it from spinning? DrPredablox 153 — 7y
0
So would you suggest I create my own weld concept? Maybe a loop that updates the CFrame, maintaining position above head? To then use CFrame Angles to create the spin? Pejorem 164 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

You can rotate/spin the duck using CFrame.Angles,

CFrame CFrame.Angles(number rX, number rY, number rZ)

So you can modify the CFrame to point in a certain direction, and if you want to make it rotate continuously try slapping that in a loop.

Another way would be to use Body Angular Velocity in the duck, which won't necessarily need to be put in a loop because it constantly applies force. I believe you would want to change the Vector3 Angular Velocity property to make it spin in a certain direction, then you can play with the other properties to make it spin however fast you want.

I'm not too sure how a weld might affect this though -- I do know that Body Angular Velocity will not work with anchored objects though iirc.

Ad

Answer this question