.Touched is unreliable, :GetTouchingParts() is even worse- what do I use for hit detection when a part’s AssemblyLinearVelocity is greater than 100?
you can simply just use raycasts
can you like
give me an example
of how i could use that
because of thought about it
but im not sure if it would work great
local Result = workspace:Raycast(launchFrom, direction, params)
if Result then
-- do something
end
dude yes i know how raycasting works but how do i use it for this scenario
like
I need to detect if a part is touching another part to weld it to the hit part
he explained it, every heartbeat (or renderstepped if its a client detection) raycast from the objects position with its velocity to see if it’ll hit something
ok
look
i want randomly flying objects
so like objects propelled by explosions or whatever
to stick to the player if it hits them as if piercing them
meaning theres no linear velocity to raycast with
like shrapnel from a grenade? im a little bit confused on what you mean by that
yeah pretty much thats a decent way to put it
if thats the case and its a random project being pushed outwards from an explosion center, there is a linearvelocity to do that with
this basically just creates an “explosion” at the world origin and sends 30 random rays out with a max magnitude of 60 studs, if it hits a player it damages em’ by 15.
local explosionCenter = Vector3.new(0,0,0)
for i = 1,30 do
local shrapnelDir = Vector3.new(Random.new():NextNumber(-1,1),Random.new():NextNumber(-1,1),Random.new():NextNumber(-1,1))
local rayRes = workspace:RayCast(explosionCenter,(shrapnelDir/shrapnelDir.Magnitude)*60)
if rayRes then
local char = rayRes.Instance.Parent
local hum = char:FindFirstChild'Humanoid'
if hum then
hum:TakeDamage(15)
end
end
end
dude
no
what i meant was that yes the part is similar to shrapnel as it is small flying and pierces the player
but no it is not always going to be from an explosion and again i just need a way to check if an actual part is touching the player not “theoretically would the part touch it” or something
i don’t think you understand how this works. whether or not its from an explosion or not, this does detect the collisions. if you’re going so fast that .Touched physically doesn’t respond than you can only detect it with raycasts. its not predicting whether or not it’ll hit, its working ahead of the system, you use that to detect the collision the frame ahead when the game can’t because the part is going too fast.
yes
i do understand how this works
you are simulating a bunch of shrapnel flying out from a specific point
this is not what i want
however it does occur to me that i can simply apply the same principle of shooting several rays in random directions from the center of my shrapnel piece to simulate kind of a hitbox and just detect if any of the rays hit a body part instead
so i guess that kinda helped thanks