@omaraa and I were talking about moving a part around but without having to worry about the problems with positioning.* We are both wondering why in the world Roblox has .Touched not working with CFraming parts as it seems like it should to make everything much easier. The wiki even says “This event does not fire if the part is being CFramed through something.” on the .Touched page. This seems like something that shouldn’t be as the only way to detect collisions with other parts would be to iterate over everything and see if they collide and this would be even more difficult with spheres, cylinders, triangles and custom geometric shapes.
Can somebody tell me why .Touched doesn’t work with CFraming or how I could possibly get around it easily? Thanks. If there is no simple way or workaround, then why can’t this be implemented by Roblox?
*changing .Position will automatically move the part above any objects that it would otherwise be colliding with
You almost answered your own question there. You’re right, it would have to iterate through the other parts to determine if anything touched it. Making this happen every time somebody updates the CFrame of a part would have a massive performance hit on all games that do this.
@Khanovich can explain this a lot better than I can though.
The way it works is that during PhysicsEngine frame we do the following:
Broadphase to find potentially touching objects
NarrowPhase to find touching objects → This triggers a Touched event.
If you zoom your context further out, you can imagine that the ROBLOX Engine works like this (Not exactly but you get the idea) →
Receive Network Packets
Process Packets
Scripts
Physics
Rendering
If you are CFraming parts in a script, you are doing this inside of the “Script” phase of the engine, where until you “yield” by either calling “wait()” or another function that yields, you are holding the Physics from being run. Therefore no Touch events can be processed. CFrames get updated by users so much that to confirm physics updates every time a CFrame changes would be too expensive.
Since you know the context of your CFrame updates, you can check for GetTouchingParts like DermonDarble suggested, but calling this every update would also be pretty expensive.