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

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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
Ad

Answer this question