Position of contact on a .Touched function?

Is there some kind of parameter on .Touched that returns the position where a part was touched?
If so, I really need it…

3 Likes

U return the pos.
script.Parent.Touched:Connect(function(part)
print(part.Position)
end)

I mean the position where a part was touched, not the position of the part touched.

Please ensure that you follow Scripting Support category guidelines when requesting help. Your thread is relatively vague and there’s no indication that you’ve searched or attempted to resolve this problem. If you had searched and gone to the BasePart.Touched documentation, you’ll notice that no such parameter exists. You’ll have to calculate this yourself.

Worth the stretch, but have you attempted to compare the relative CFrame of the part in contact to the one that’s checking for the contact?

part.Touched:Connect(function (otherPart)
    local contactPoint = part.CFrame:ToObjectSpace(otherPart.CFrame)
    -- Do something here
end)

@DrakeNightingale Returning the other part’s position doesn’t give you a contact point and magnitude won’t give you the result you’re looking for, since that’s for equations requiring distance.

6 Likes

The difficulty in this type of question is that collision between two parts likely cannot be defined as just one point of contact.

Take for example the idea of two equal sized parts stacked on top of each other. In that case any point on the two colliding surfaces would be considered a point of contact; that’s an infinite number of points!

Could you perhaps explain what you’re trying to do with it?

3 Likes

If you want the exact point at which something touches something I’d recommend Raycasting.

4 Likes

I suppose what u can do is on contact get a vector between the part that touched it and the actual part itself. From there cast it as a ray and have it whitelist only the part that collided. Make the origin of the ray in a sense be the part which collided. Then from there its just ray.Position

2 Likes

That might be unreliable. Say you have a projectile that is travelling fast, and has CanCollide set to false. If it hits a wall that’s 1 stud thick, it’ll most likely have already reached the other side by the time the Touched event is fired; the raycast you’d perform would give you a position on the side of the wall opposite to the side that was first contacted.

I know it’s been a year since this got posted, but
you can try raycasting, but its still not exact and somtimes it doesn’t work on a
large plane surface.

part.Touched:Connect(function(hit)
			if hit:IsA("BasePart") and then
				
				local Params = RaycastParams.new()
				Params.FilterType = Enum.RaycastFilterType.Exclude
				Params.FilterDescendantsInstances = {script.Parent}
				
				local raycast = workspace:Raycast(part, hit.Position, Params)
				if raycast then
					ExactHit = raycast.Position
				end
			end

The script can be improved.

There is a new way, better and easier than Raycasting: Spherecasting

Currently only these two are supported:

So it might not meet everyone’s needs in this particular use case, but, with some imagination it can probably meet most.

3 Likes