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

How to CFrame in the direction you're looking?

Asked by
JJ_B 250 Moderation Voter
8 years ago

I made a tool that moves your character in the direction that you're looking (supposedly,) however it does not work. Here is the script:

script.Parent.Equipped:connect(function()
    while true do
        local cf = game.Players.LocalPlayer.Character.Torso.CFrame
        cf = cf + Vector3.new(2,0,0)*cf.lookVector
        wait(0.2)
    end
    wait(0.1)
end)

It only moves me left or right depending on how I'm looking, rather than any direction. Help?

2 answers

Log in to vote
2
Answered by
Spectrobz 140
8 years ago
local cf = game.Players.LocalPlayer.Character.Torso.CFrame
 cf = cf * cf.lookVector

Vector3 will move your character depending on the world's X,Y,Z axis. LookVector is what you want to use.

If you want to move by 2 studs, you would multiply the direction by 2.

local cf = game.Players.LocalPlayer.Character.Torso.CFrame
 cf = cf * (cf.lookVector * 2)
1
It would be '+' (cf.lookVector*2) not '*' JJ_B 250 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago
player = game.Players.LocalPlayer
script.Parent.Activated:connect(function()
    while true do
    player.Character.Torso.CFrame = player.Character.Torso.CFrame*CFrame.new(0,0,-2)
    wait(0.2)
    end
wait(.1)
end)

Answer this question