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

How do I find the direction the player is moving relative to camera?

Asked by 4 years ago
Edited 4 years ago

I'm trying to create a dash for my game, so when the camera is facing the back of the camera and the player is holding S, the character dashes back, however if the camera is looking at the front of the character and the character is holding S, ill need the character to dash forward.

local DashEvent = game:GetService("ReplicatedStorage").Remotes.DashEvent
local LastDash = tick()-4
DashEvent.OnServerEvent:Connect(function(Player,CLookVector,CRightVector)
    local CanDash = math.abs(tick()-LastDash)
    if CanDash > 2 and Player.Character and Player.Character.HumanoidRootPart then
        LastDash = tick()
        local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
        BodyVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
        BodyVelocity.Velocity = CLookVector*-30
        game.Debris:AddItem(BodyVelocity,.2)
    end
end)

Thanks!

Answer this question