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

How To Make A Vector3(MoveVector) Relative To The Camera?

Hello, I have been trying to make the player's ControlModule:GetMoveVector() relative to the camera for a flying camera drone. I have been googling this and going through countless results for a few hours now and still have had no luck, any time I have gotten movement from the drone it has been on a flat plain like normal but the speed it moved depended on where I was looking. I am trying to make it so that when I hold w/joystick forwards the drone will move towards my camera, and the others would also be relative like that. ANY help is appreciated. My code atm:

repeat
	local CamVector = Camera.CFrame.LookVector
	local MoveVector = require(Plr:WaitForChild("PlayerScripts").PlayerModule:WaitForChild("ControlModule")):GetMoveVector()
	local ModifiedVector = (MoveVector*CamVector)*Speed

	print(ModifiedVector)
	CurrentKino.PrimaryPart.BodyVelocity.Velocity = ModifiedVector

	wait()
until CurrentKino == nil

1 answer

I got it to work, I took the individual forward/backward, left/right values and multiplied them by their corresponding CFrame.Vectors.

repeat
    local MoveVector = require(Plr:WaitForChild("PlayerScripts").PlayerModule:WaitForChild("ControlModule")):GetMoveVector()
    local MoveX = MoveVector.X
    local MoveZ = MoveVector.Z
            
    MoveX = Camera.CFrame.RightVector*MoveX
    MoveZ = Camera.CFrame.LookVector*-MoveZ
    MoveVector = (MoveX+MoveZ)*Speed
    
    --local ModifiedVector = (MoveVector*CamAngles)*Speed

    print(MoveVector)
    CurrentKino.PrimaryPart.BodyVelocity.Velocity = MoveVector

    wait()
until CurrentKino == nil

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