-
What do you want to achieve? Keep it simple and clear!
I want my bullets to phase/go through these parts(the magenta and yellow one) who’s size is 0.1(Magenta is 0.1 in X and Yellow is 0.1 in Z) using fastcast -
What is the issue? Include screenshots / videos if possible!
Issue -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried finding the surface it’s hitting like if it’s at the front/back or left/right, switched some variables and stuff…
Line(CanRayPierce):
elseif hitPart.Size.X <= 2 and hitPart.Size.X < hitPart.Size.Z and getRelativeNormal(hitPart, hitNormal) == Enum.NormalId.Left or getRelativeNormal(hitPart, hitNormal) == Enum.NormalId.Right then
print('1')
return true
elseif hitPart.Size.Z <= 2 and hitPart.Size.Z < hitPart.Size.X and getRelativeNormal(hitPart, hitNormal) == Enum.NormalId.Front or getRelativeNormal(hitPart, hitNormal) == Enum.NormalId.Back then
print('2')
return true
elseif (hitPart.Size.X == hitPart.Size.Z) and hitPart.Size.X <= 2 and hitPart.Size.Z <= 2 then
return true
end
Line(RayPierced):
elseif part.Size.Z < 2 and part.Size.X < part.Size.Z and getRelativeNormal(part, normal) == Enum.NormalId.Front or getRelativeNormal(part, normal) == Enum.NormalId.Back then
cast:SetVelocity(segmentVelocity.Unit * segmentVelocity.Magnitude)
cast:SetPosition(position)
print('phaseX')
elseif part.Size.X < 2 and part.Size.Z < part.Size.X and getRelativeNormal(part, normal) == Enum.NormalId.Left or getRelativeNormal(part, normal) == Enum.NormalId.Right then
cast:SetVelocity(segmentVelocity.Unit * segmentVelocity.Magnitude)
cast:SetPosition(position)
print('phaseZ')
elseif (part.Size.X == part.Size.Z) and part.Size.X < 2 and part.Size.Z < 2 then
cast:SetVelocity(segmentVelocity.Unit * segmentVelocity.Magnitude)
cast:SetPosition(position)
print('phaseXZ')
end
getRelativeNormal:
local function getRelativeNormal(hitPart, surfaceNormal)
local relativeNormal = (hitPart.CFrame - hitPart.Position):Inverse() * surfaceNormal
if math.abs(relativeNormal.X) >= 0.99 then -- choose by axis
return math.sign(relativeNormal.X) == 1 -- choose by sign
and Enum.NormalId.Left
or Enum.NormalId.Right
elseif math.abs(relativeNormal.Y) >= 0.99 then
return math.sign(relativeNormal.Y) == 1
and Enum.NormalId.Top
or Enum.NormalId.Bottom
elseif math.abs(relativeNormal.Z) >= 0.99 then
return math.sign(relativeNormal.Z) == 1
and Enum.NormalId.Front
or Enum.NormalId.Back
end
return nil
end