Hello
I have a big anchored part and a smaller moving part which hits the anchored part.
The smaller part does not move in a straight direction before the hit.
Is there some way to get the coordinates where the touch happened?
When the Touched event fires the small part is not too close anymore to the point of the hit.
(the Roblox engine should know where the hit happened, because it physically simulates the bounce at these coordinates)
local bigPart = workspace.bigPart
local smallPart = workspace.smallPart
local function onTouched(otherPart)
local rayOrigin = otherPart.Position -- Cast from smallPart
local rayDirection = bigPart.Position -- Cast to bigPart
local raycastResult = workspace:Raycast(rayOrigin, rayDirection) -- Begin raycasting
if raycastResult ~= nil then -- Once the ray hit the bigPart, return the position where the ray hits.
print(raycastResult.Position)
end
end
bigPart.Touched:Connect(onTouched)
local bigPart = workspace.bigPart
local smallPart = workspace.smallPart
local function onTouched(otherPart)
local rayCastParams = RaycastParams.new()
local rayOrigin = otherPart.Position
local rayDirection = (bigPart.Position - otherPart.Position).Unit * 9e9
local raycastResult = workspace:Raycast(rayCastParams, rayOrigin, rayDirection)
if raycastResult ~= nil then
print(raycastResult.Position)
end
end
bigPart.Touched:Connect(onTouched)
It is even worse, because at the time when OnTouched event fires the small part is below the big part (falling due to gravity) so the raycast may not hit at all the correct side of the big part.
this is because of network ownership and the physics step not running in sync with luau
the computer that currently has ownership should be detecting the touch
you can set the networkowner to nil so that the server keeps ownership and then the touch event should fire at the correct time on server scripts
another problem is that the physics engine does not run in sync with luau code so it also possible that the physics step can run multiple times after the touch before the luau event even gets fired