I want to modify the force that objects receive when they collide.
Consider a racing game. I want some NPCs running around to keep the sidewalks feeling alive, and I want them to ragdoll when the player hits them, but I don’t want them to interrupt gameplay by actually slowing down the car. Same for destructible physics objects like street lights and fences. Same for physics debris like tumbling parts from an opponent’s destroyed car.
I want to register a callback on the car’s collider that gets invoked whenever the physics engine calculates impact force between the car and another object. I want to receive information about the contact and the force that the physics engine intends to apply to the assemblies involved in the collision. I want to be able to return a modified value that represents the way I want the physics engine to actually handle this collision. This type of API is consistent with other APIs like text chat processing.
As an example,
collider:RegisterTouchHandler(function(context)
if not context.other:HasTag("PhysicsDebris") then return end
context.selfOutputVelocity = context.selfInputVelocity
return context
end)
Invoking luau this way is potentially very expensive. That’s fine. I only want to do this for gameplay-critical objects. I can handle my own game’s performance.
This isn’t just useful for racing games. This is useful any time a game requires a physics interaction that isn’t enabled by physics constraints. Many such interactions don’t make sense as platform-level constraints anyway.
- High-realism tire traction for a car simulator. Requires considerations like temperature and wetness.
- High-realism bullet physics for a tactical shooter. Requires considerations like bullet spin, impact angle, and material density.
- Client-side, gameplay-irrelevant debris. Such as broken glass from a shot window. Should never affect player movement, but should still get kicked around as the player walks around.
- Gameplay-critical unstoppable forces. Such as a large padded cylinder that knocks players into the water in an obby. Should never slow down from collisions with players.