Ad
Log in to vote
0

How do I make blocks one directional?

Asked by
Pejoume 11
13 days ago
Edited 13 days ago

So I'm working on a combat system and I know how to make blocking and stuff work, but my issue is that I don't know how to make it so if you punch the person that's blocking from behind it breaks their block. If anyone could help me with this issue I'd greatly appreciate it, all I need is a function to see if a player is facing another player or a small example to work off of.

0
Dot products :) Puppynniko 419 — 13d

2 answers

Log in to vote
0
Answered by 13 days ago

You can use Dot Products to see if a part is seen in another part's field of view. It basically returns 0.5 to 1 if the part is in front of another part and returns 0 or less if it's in the side/back. Here's a YouTube tutorial if you want.

local part1 = workspace.Part1
local part2 = workspace.Part2

while true do
    task.wait(1)
    local partToPart = (part2.Position - part1.Position).Unit

    local dotProduct = partToPart:Dot(part1.CFrame.LookVector)

    if dotProduct >= 0.5 then -- if part is within the part1's field of view
        print("Part2 is within Part1's FOV")
    else
        print("Part2 cannot be seen in Part1's FOV")
    end
end
Ad
Log in to vote
0
Answered by 13 days ago
Edited 13 days ago

Use raycasting.

local part1 = workspace.Part1
local part2 = workspace.Part2

local params = RaycastParams.new()
params.FilterType = Enum.FilterType.Blacklist
params.FilterDescendantsInstances = {part1}

local length = 50

while true do
    local hit = workspace:Raycast(part1.Position, part1.CFrame.LookVector * length)
    if hit and hit.Instance then
    --do code
    end
    task.wait(0.2)
end

Answer this question