So i making a tank game but i have to figure out how to calculate the relative armor thickness of a part to see if the round goes through or stopes/bounces but idk how to do that with the FastCast module. Ive look around but im bad at math so idk what i should be doing.
Isnt there a Property in Custom Properties
for Thickness?
idk, could you explain it a bit more?
Looking at it (Just logged in), There are the Properties Mass
and Density
Not sure if Density
is what you’re looking for
To Access it, Enable CustomPhysicalProperties
I need the relative thickness of a part from a bullet, not Mass or Density
In other words, Density
is Thickness
I think you need to take the entrance and exit positions from a raycast and then find the distance between the two vectors.
I believe he is asking how to calculate the distance a bullet needs to travel upon impacting the part to completely travel through it.
yes, but i have no idea on how to do this with the FastCast module that im using, this is the code that i currently have:
local FastCast = require(game.ReplicatedStorage.FastCastRedux)
local Rounds = workspace.TankRounds
local Caster = FastCast.new()
local TankRoundInfo = {
APFSDS = {
CanPen = 500
},
}
-- Configs
local Speed = 100
local CastParams = RaycastParams.new()
local CastBehavior = FastCast.newBehavior()
local Bullet = Instance.new("Part")
Bullet.Shape = "Ball"
Bullet.Material = Enum.Material.Neon
Bullet.Color = Color3.new(1, 0, 0)
Bullet.Size = Vector3.new(0.5,0.5,0.5)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Name = "APFSDS"
Bullet.Parent = Rounds
CastBehavior.Acceleration = Vector3.new(0,-(Speed/100),0)
CastBehavior.CosmeticBulletContainer = Rounds
CastBehavior.CosmeticBulletTemplate = Bullet
CastParams.FilterType = Enum.RaycastFilterType.Blacklist
CastParams.IgnoreWater = true
CastParams.FilterDescendantsInstances = {Rounds}
local UpdateBullet = function(cast, lastPoint, direction, length, speed, bullet)
if bullet then
local BulletLength = bullet.Size.Z/2
local Offset = CFrame.new(0,0,-(length - BulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint+direction):ToWorldSpace(Offset)
end
end
Caster.LengthChanged:Connect(UpdateBullet)
local RoundHit = function(cast, result, speed, bullet)
local Hit = result.Instance
-- Check if the bullet can pen the the armor
game:GetService("Debris"):AddItem(bullet,0)
end
Caster.RayHit:Connect(RoundHit)
local Fire = function()
local Origin = workspace.Gun.FirePoint.WorldPosition
local EndPoint = (workspace.Gun.EndPoint.WorldPosition - Origin).Unit
Caster:Fire(Origin,EndPoint,Speed,CastBehavior)
end
game.ReplicatedStorage.FireGun.OnServerEvent:Connect(Fire)
I’m not quite familiar with FastCast, but if it returns the impact position then you can make a second cast from the opposition direction with only the impacted part whitelisted to calculate the exit point of the shot. Once you have those two points, you can simply subtract them from each other and calculate the magnitude of the resultant vector using the Pythagorean theorem. This should work for convex parts.
Here are some similar posts that might help you:
how-do-i-measure-the-part-thickness-using-a-ray-cast
how to find the exit point of a ray
im trying that but it just doesnt work, idk what im doing wrong
local Orign = result.Position
local NewOrign = Vector3.new(Orign.X+10,Orign.Y,Orign.Z)
local a = Instance.new("Part")
a.Parent = workspace
a.Position = NewOrign
a.Anchored = true
a.Size = Vector3.new(1,1,1)
local test = workspace:Raycast(NewOrign,Orign)
print(test) -- nil
print(CalculateDisatance(result.Position,test.Position))
also if i rotate my test it places the second ray in the wrong pos, how do i fix that?
To calculate the NewOrigin you need to also take the direction of your first Cast into consideration. Instead of just translating the impact point in the X-direction, you’ll need to translate it in the direction of the velocity of your initial shot when it hit the armor. This way, your second raycast will always be in the opposite direction of the first one.
Can you please elaborate on what you were doing with the test? If you were expecting the raycast to return the part you created, it returned nil because you started the raycast inside of the part and raycasts probably can’t detect hitting the inside of a surface.
could you give me a code sample of the second ray?
in the test i tried to make the second ray but it doesnt work
is there any other way to calculate the thickness of a part?
Ive found the solution for this, here is the code if anybody needs it!
local FastCast = require(game.ReplicatedStorage.FastCastRedux)
local Rounds = workspace.TankRounds
local Caster = FastCast.new()
local TankRoundInfo = {
APFSDS = {
CanPen = 5 -- how many studs it can pen
},
}
-- Configs
local Speed = 200
local CastParams = RaycastParams.new()
local CastBehavior = FastCast.newBehavior()
local Bullet = Instance.new("Part")
Bullet.Shape = "Ball"
Bullet.Material = Enum.Material.Neon
Bullet.Color = Color3.new(1, 0, 0)
Bullet.Size = Vector3.new(0.5,0.5,0.5)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Name = "APFSDS"
Bullet.Parent = Rounds
CastBehavior.Acceleration = Vector3.new(0,-(Speed/100),0)
CastBehavior.CosmeticBulletContainer = Rounds
CastBehavior.CosmeticBulletTemplate = Bullet
CastParams.FilterType = Enum.RaycastFilterType.Blacklist
CastParams.IgnoreWater = true
CastParams.FilterDescendantsInstances = {Rounds}
local UpdateBullet = function(cast, lastPoint, direction, length, speed, bullet)
if bullet then
local BulletLength = bullet.Size.Z/2
local Offset = CFrame.new(0,0,-(length - BulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint+direction):ToWorldSpace(Offset)
end
end
Caster.LengthChanged:Connect(UpdateBullet)
local RoundHit = function(cast, result, speed, bullet)
local Hit = result.Instance
for i,v in pairs(TankRoundInfo) do
if i == bullet.Name then
local CastParams2 = RaycastParams.new()
CastParams2.FilterDescendantsInstances = {Hit}
CastParams2.FilterType = Enum.RaycastFilterType.Whitelist
local Origin = result.Position
local NewOrign = Origin + (workspace.Gun.MaxRange.WorldPosition - Origin).Unit * v.CanPen
local CanPen = workspace:Raycast(NewOrign, Origin-NewOrign,CastParams2) -- if it is nil it cant pen the armor
if CanPen then
CanPen = true
else
CanPen = false
end
print(CanPen)
end
end
game:GetService("Debris"):AddItem(bullet,0)
end
Caster.RayHit:Connect(RoundHit)
local Fire = function()
local Origin = workspace.Gun.FirePoint.WorldPosition
local MaxRange = (workspace.Gun.MaxRange.WorldPosition - Origin).Unit
Caster:Fire(Origin,MaxRange,Speed,CastBehavior)
end
game.ReplicatedStorage.FireGun.OnServerEvent:Connect(Fire)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.