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

Help on a player rotation script?

Asked by 10 years ago

What I was trying to make was simply a script that rotated your player to face your mouse. This was the script I came up with (LocalScript)

local p = game.Players.LocalPlayer
repeat wait() until p.Character
local c = p.Character
local m = p:GetMouse()
local rs = game:GetService("RunService")
local tb = Instance.new("Part", Workspace.CurrentCamera)
local cc = Workspace.CurrentCamera
tb.CanCollide = false
tb.Transparency = 1
tb.Anchored = true
tb.FormFactor = "Custom"
tb.Size = Vector3.new(0.2,0.2,0.2)
tb.CFrame = c.Torso.CFrame *CFrame.new(0,15,5)
local tc = Instance.new("Part", Workspace.CurrentCamera)
tc.Transparency = 1
tc.CanCollide = false
tc.FormFactor = "Custom"
tc.Size = Vector3.new(0.2,0.2,0.2)
bpos = Instance.new("BodyPosition", tc)
bpos.maxForce = Vector3.new(math.huge, math.huge, math.huge)
bpos.position = tb.Position

rs.RenderStepped:connect(
function()
    dist = (c.Torso.Position-m.Hit.p).magnitude
    if dist > 8 then
        c.Torso.CFrame = CFrame.new(c.Torso.Position, Vector3.new(m.Hit.p.x, c.Torso.Position.y, m.Hit.p.z))
    end
    cc.CoordinateFrame = CFrame.new(tc.Position, c.Torso.Position)
    tb.CFrame = c.Torso.CFrame *CFrame.new(0,10,20)
    bpos.position = tb.Position
end)

I found that when I used this, some controls were affected and the player went in strange directions rather than going in the direction that I would have liked. Is there anyway to get around this problem?

0
Someone please help me on this ^~^ xolbStudios 127 — 10y

1 answer

Log in to vote
0
Answered by 9 years ago

Its simple. Simply do this:

part.CFrame = CFrame.new(part.Position,mouse.Hit.p)

part is the part you want to rotate towards mouse. In this case, since you want the player to rotate towards mouse, make that part Torso. You can make the head, arm, whatever, but since the Character object is welded together, it doesnt' matter which part your rotating it does it together.

So basically

player.Character.Torso.CFrame = CFrame.new(player.Character.Torso.Position,mouse.Hit.p)

Define player in your script, copy this, and your good to go.

Your welcome.

Ad

Answer this question