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

Model Moving rotates upwards with mouse?

I made this model which does rotate in the direction of the mouse, but once the mouse moves towards the center of the model, it tilts upwards or downwards. The script works, but moving upwards or downwards isn't what I intended the script to do

It's a local script

Cannon = game.Workspace.Cannon
player = game.Players.LocalPlayer
mouse = player:GetMouse()

local prev_mouse_hit 

	mouse.Button1Up:connect(function()
end)

	mouse.Button1Down:connect(function()
end)

	mouse.Move:connect(function()
		if mouse.Hit.p ~= prev_mouse_hit then
			Cannon:SetPrimaryPartCFrame(CFrame.new(Cannon.PrimaryPart.Position,Vector3.new(mouse.Hit.p.x,0,mouse.Hit.p.z))) 
			prev_mouse_hit = mouse.Hit.p
	end
end)

1 answer

Ok, the issue was that the model would look at the area right near it, and it's position would change a little.

mouse.Move:connect(function()
	if mouse.Hit.p ~= prev_mouse_hit then
		local vect = Cannon.PrimaryPart.Position
		Cannon:SetPrimaryPartCFrame(CFrame.new(Vector3.new(vect.X,0,vect.Z),Vector3.new(mouse.Hit.p.x,0,mouse.Hit.p.z)))
		prev_mouse_hit = mouse.Hit.p
--also, why the prev_mouse_hit thing?
--this works because it forces the y on rotation and position to be 0, but if you need the y to be different, then just make it like 10 or something
    end
end)

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