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

How to CFrame in the direction you're looking?

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

✓ Accepted answer
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 comment

1

It would be '+' (cf.lookVector2) not ''

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)

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