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

How do you check whether a character is facing closer to forward or backwards relative to a part?

Asked by 5 years ago

I'm trying to make it so that if you are closer to facing to the front relative to the part, then it will print "forward," but if you're closer to facing the opposite direction of the part it will print "backward."

I'm really confused as to how I can check this. I'm trying to use lookVectors, but I honestly don't know what to do with the lookVectors and I'm pretty much lost on how to do this.

Here's my current script, as I am just trying to get the direction part working, but not much is going on here:

local CollectionService = game:GetService("CollectionService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

humanoid.Touched:Connect(function(hit)
    if CollectionService:HasTag(hit, "RopePart") then
        local forwardlookVector = hit.CFrame.lookVector
        local backwardlookVector = hit.CFrame.lookVector * Vector3.new(-1, 1, -1)
        local characterlookVector = character.HumanoidRootPart.CFrame.lookVector

        local averageVector = (forwardlookVector + backwardlookVector)/2

        --[===[if characterlookVector >= averageVector then
            print("forward")
        elseif characterlookVector < averageVector then
            print("backward")
        end]===]
    end
end)

Answer this question