Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 comment

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)

1 answer

✓ Accepted answer
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

2 comments

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

0

Lastly, upon combining a CFrame with another to adjust the current CFrame, you must multiply both userdatas together, you cannot add CFrames

This discussion is preserved as it was. New answers, comments, and votes are closed.