So im making an “advanced” destruction game and, i need to detect the hit point to apply the damage properly. I figured out a way to get the hit point and other information using “Union Operation”.
The problem is that when i try to use my “Hole Union” module to get the information, it return an error saying that im referencing nil(Union result) because the part and the “Hit Part” are not touching one another.
I did look in the Devforum and found postes that where talking about that but, in my case if there is even 1ms(Which will happend a lot lol) of delay it would break the whole game.
Tried solutions :
-
Get the part linear velocity then inverting it and raycasting in that direction. Do not work if the “Hit Part” is small or if the part did hit around the center of the “Hit Part”
-
Get delay of the Event. Did not work cause the delay change every time(If you think you have a solution with this you can explain it cause i did not test this at 100%).
The code above is the code that i use for testing but, the code that i use to get the information is not important in this case cause it dont cant even work if both part are not touching.
I tested it one a part with a BodyAngv and BodyVel which the Angular disable angular motion and the Velocity disable all motion except the Y one. The part was touching a part with 1 elasticity and 100 elasticity wheight and zero gravity. If you want you can try it as you want because i tested it like 80 time in a lot of different situation.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollisionDetection = require(ReplicatedStorage.AdvancedPhysic.CollisionDetection)
local Part = script.Parent
local D = false
--CollisionDetection:AdvancedAdd({script.Parent})
local A = Vector3.new(0, 0, 0)
script.Parent.Touched:Connect(function(Hit)
local P = Part.Position
D = true
Part.Anchored = true
Part.Position = P
print(Hit)
local Elasticity = (Part.CustomPhysicalProperties.Elasticity * Part.CustomPhysicalProperties.ElasticityWeight + Hit.CustomPhysicalProperties.Elasticity * Hit.CustomPhysicalProperties.ElasticityWeight) / (Part.CustomPhysicalProperties.ElasticityWeight + Hit.CustomPhysicalProperties.ElasticityWeight)
local DD = Part.AssemblyLinearVelocity / Elasticity
print(((Part.Position.Y - Part.Size.Y / 2) - 21.003) / math.abs(A.Y))
print((Part.Position.Y - Part.Size.Y / 2) - 21.003)
print((0.015059300257487) * 1.74)
Part.Position = Vector3.new(Part.Position.X, Part.Position.Y - (0.015059300257487) * 1.74, Part.Position.Z)
print(((Part.Position.Y - Part.Size.Y / 2) - 21.003))
end)
while wait(0.00001) do
if D == false then
A = Part.AssemblyLinearVelocity
print(A)
end
end
```Im sorry if it is really unorganized and if it look bad but it is because it a "Test" code.