Hi. I am a novice scripter wanting to make a mechanic that puts the player in a controllable bubble.
I have made most of the mechanic, however I am currently unable to finish the mechanic due to my lack of knowledge on how to rotate something based off of where the camera is looking
(So say for example I wanted to use W to move forward, I am currently not sure on how to make it go forward relative to the camera.)
If anyone could show me some methods on being able to achieve this I would greatly appreciate it.
You should use the LookVector of the cameras CFrame for forwards & backwards, and RightVector for Left and Right. (Simply use -RightVector
for left, and -LookVector
for backwards.)
If you'd add all these units up to a single vector, you'd be able to also move diagonaly.
Eg.
local Cam = workspace.CurrentCamera local UIS = game:GetService("UserInputService") local Vel game:GetService("RunService").RenderStepped:Connect(function() Vel = Vector3.new(0,0,0) if UIS:IsKeyDown(Enum.KeyCode.W) then Vel = Vel + Cam.CFrame.LookVector end if UIS:IsKeyDown(Enum.KeyCode.S) then Vel = Vel - Cam.CFrame.LookVector end if UIS:IsKeyDown(Enum.KeyCode.D) then Vel = Vel + Cam.CFrame.RightVector end if UIS:IsKeyDown(Enum.KeyCode.A) then Vel = Vel - Cam.CFrame.RightVector end Vel = Vel * Vector3.new(1,0,1) -- Removes 'flight' lol. --Add & do whatever you want to the value here. end)