#Wall banging with raycast

1 messages · Page 1 of 1 (latest)

tranquil nimbus
#

Im working on a projectile module with wall banging feature, how would I calculate the thickness of the object that mt projectile might go through

hollow flower
stone hatch
#

So you'd need to figure out what size to use based on where the projectile hit the wall

hollow flower
#

I can see how their could be edge cases but I’m confused on the wording of the one you said

stone hatch
# hollow flower I can see how their could be edge cases but I’m confused on the wording of the o...

Say you always assume that the width of the wall a bullet will travel through is the X size of that wall. This might work perfectly well when you shoot at the wall from the front, however when you try shooting at the side of the wall, it will also go through even if the length of wall the bullet traveled through is way too long because it doesn't account for the fact that you shot at it from the side

hollow flower
#

Ohhh I get what your saying

hollow flower
# tranquil nimbus Im working on a projectile module with wall banging feature, how would I calcula...
--Services
local InputService = game:GetService('UserInputService')
local Players = game:GetService('Players')

--Player
local Player = Players.LocalPlayer

--Objects
local Tool = script.Parent

--Raycasting Parameters
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Player.Character, workspace.Baseplate}
Params.FilterType = Enum.RaycastFilterType.Exclude

--Variables
local MaxWallWidth = 1.5

--[[Code]]
local function Raycast()
    --Mouse Position
    local MousePos = InputService:GetMouseLocation()

    --Raycast positionings
    local MouseRayCast = workspace.CurrentCamera:ViewportPointToRay(MousePos.X, MousePos.Y)
    local MuzzlePosition = Player.Character.HumanoidRootPart.Position
    
    --Raycast Result
    local Raycast = workspace:Raycast(MuzzlePosition, MouseRayCast.Direction * 100, Params)
    
    --Return the raycast
    if Raycast == nil then
        return nil
    else
        return Raycast
    end
end

local function CheckResultSize(RayCast)
    --Get the ray instance
    local RayResult = RayCast.Instance
    
    if not RayResult:IsA("Part") then return end
    
    --Get the sizes
    local ResultSizeX = RayResult.Size.X
    local ResultSizeZ = RayResult.Size.Z

    
    --Check the normal
    local Normal = RayCast.Normal
    local ResultCFrame = RayResult.CFrame
    local PartSize = RayResult.Size
    
    local LocalNormal = ResultCFrame:VectorToObjectSpace(Normal)
    if math.abs(LocalNormal.X) > 0.85 then
        if ResultSizeX > MaxWallWidth then
            print("X too thick")
            return
        end
    elseif math.abs(LocalNormal.Z) > 0.85 then
        if ResultSizeZ > MaxWallWidth then
            print("Z too thick")
            return
        end
    end
    
    print("Went through!")
end

Tool.Activated:Connect(function()
    local Raycast = Raycast()
    
    if Raycast == nil then 
        print("hit nothing")
        return 
    end
    
    CheckResultSize(Raycast)
end)
#

I made it all client side cause I was too lazy

#

here is the Tool Descendants / layout

#

At first I started using angles but I was having a tough time, I prompted it eventually cause I was getting lazy and it pointed me towards normals and it works well

tranquil nimbus
#

Ale thanks i got it