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

How to make Torso Follow Mouse?

Asked by 9 years ago

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

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

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? dragonkeeper467 453 — 9y
0
Thanks so much! dragonkeeper467 453 — 9y
Ad

Answer this question