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

How to make Torso Follow Mouse?

I want it so that in 3rd person view(zoomed out) when your mouse moves around your torso, specifically your whole character follows the mouse, I already have it so that the arms are welded and go up and down with the mouse but I wish for the torso to always face the mouse and be able to spin the Char around in 3rd person.

This is what I have so far, DON'T WRITE THE SCRIPT FOR ME, this isn't a request site, I just need some guidance as to how to do it, you can write bits a pieces of the complicated parts that I may not understand such as math.asin ect.

function Equipped() --Function called when gun is selected
	
	local ArmWeld = Instance.new("Weld")
	ArmWeld.Parent = Head
	ArmWeld.Part0 = Head
	ArmWeld.Part1 = RArm
	ArmWeld.C1 = CFrame.new(-1,0.5,-1) * CFrame.Angles(-1.5,-.5,0)

	local HeadWeld = Instance.new("Weld")
	HeadWeld.Parent = Head
	HeadWeld.Part0 = Head
	HeadWeld.Part1 = LArm
	HeadWeld.C1 = CFrame.new(1,0.5,-1) * CFrame.Angles(-1.5,.5,0)

	repeat wait() until Rsh and Lsh --Wait for the left and right shoulder.
		Rsh.Part1 = nil --Set weld Part1 to nil.
		Lsh.Part1 = nil --Set weld Part1 to nil.

	Mouse.Move:connect(function() --Runs the function each time the mouse is moved.
    	Mouse.TargetFilter = workspace --This is important when setting the C0 at the bottom as it ignores everything in the workspace to give clean movement of the arms on the Y axis.
    	Torso.Neck.C1 = CFrame.new() --Sets the C1 to a blank CFrame so the head doesn't glitch.
    	Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0) --Moves the head up by 1.5 studs and then sets the angle of your character's neck looking up towards the mouse using inverse trigonometry (A grade maths) and unit vectors (so you only get the direction.)
	end)

	Mouse.Idle:connect(function() --Runs the function when the mouse is idle.
    	Mouse.TargetFilter = workspace --This is important when setting the C0 at the bottom as it ignores everything in the workspace to give clean movement of the arms on the Y axis.
    	Torso.Neck.C1 = CFrame.new() --Sets the C1 to a blank CFrame so the head doesn't glitch.
    	Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0) --Moves the head up by 1.5 studs and then sets the angle of your character's neck looking up towards the mouse using inverse trigonometry (A grade maths) and unit vectors (so you only get the direction.)
	end)
	
	--Char(Torso, shoulders) follows mouse?!?!!?!?
end

1 answer

What you do is instead of setting any Weld property to move the Torso, you just set its CFrame directly and everything else follows, like so:

Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(Mouse.Hit.p.X, 0, Mouse.Hit.p.Z))

Just add that line inside each of the two functions, right after the TargetFilter lines.

3 comments

0

This works but, when i hold the position to the side and continue walking, it glitched and like vibrates, can i fix this at all?

0

Thanks so much!

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