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

I need help with mixing the Orientation and the Position of the cannon. Help?

Asked by 4 years ago

I have a cannon object on the front of the cannon that the cannon ball which its referencing going to the position of the cannon shoot. I need to mix the Orientation and the Position to make the cannon ball go in a certain direction.

Code here.





local direction = script.Parent.CannonShoot.Orientation local clickdetector = script.Parent:WaitForChild("ClickDetector") clickdetector.MouseClick:Connect(function() local copy = game.Workspace.Part:Clone() copy.Parent = workspace copy.Position = script.Parent.CannonShoot.Position copy.Orientation = script.Parent.CannonShoot.Orientation copy.Anchored = true while true do copy.Position = copy.Position + Vector3.new () --i need help here because i need to mix the orientation and the position wait(0.01) end end)
1
To simultaneously manage the Position and Orientation of part, you must adjust the CFrame (Coordinate Frame) userdata.  copy.CFrame = CFrame.new(copy.Position + Vector3.new(newPosition)) * CFrame.Angles(radianOrientation) Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
local clickdetector = script.Parent:WaitForChild("ClickDetector")

clickdetector.MouseClick:Connect(function()

    local copy = game.Workspace.Part:Clone()

    copy.Parent = workspace
    copy.Position = script.Parent.CannonShoot.Position
    copy.Anchored = true

    while true do
        wait(0.01)
        copy.CFrame = copy.CFrame + CFrame.Angles(90,0,0)-- set to how much you want to rotate
        copy.Position = copy.Position + Vector3.new(0,0,0)-- set to whatever position

    end

end)

This should work.

Up vote and accept if this helped!

All the best,

PrismaticFruits

0
It’s redundant to set the position outside of an existing CFrame modification. CFrames are userdata matrices that simultaneously withhold both the Position and Orientational properties of the part, you should be setting both within the CFrame adjustment . On a final note, CFrame.Angles() requires radian degree arguments, you have to call math.rad(degree) when assigning a new XYZ rotation Ziffixture 6913 — 4y
0
Lastly, upon combining a CFrame with another to adjust the current CFrame, you must multiply both userdatas together, you cannot add CFrames Ziffixture 6913 — 4y
Ad

Answer this question