Building 2D games
2D physics
Colliders, bodies, sensors, joints and gravity for 2D sprites.
Trisgine ships a 2D rigid-body solver with circles and boxes, static, dynamic and kinematic bodies, sensors, joints and collision layers.
The two components
Collider2D gives a sprite a shape. A sprite with a collider but no body is static: walls, floors and level geometry.
-Collider2D:box,halfWidth,halfHeight[,offsetX,offsetY,material][,sensor]
-Collider2D:circle,radius[,offsetX,offsetY,material][,sensor]PhysicsBody2D makes it move under physics:
-PhysicsBody2D:mass,linearDamping,angularDamping[,flags,angularVelocity,gravityScale]Flags can be combined: kinematic, fixedrotation, ccd, nosleep, reportscollisions.
A dynamic body also needs a -Velocity2D:x,y line, even if it starts at 0,0.
Scene setup
Add Physics2DStep to the update: list, and optionally a Physics2D config. Its first two
values are gravity:
configs:
-Physics2D:0,-9.81,0.0041667,8
update:
-MoveByVelocity2D
-Physics2DStep
render:
-Sprite2DRenderingA falling crate and a trigger zone
This is the engine's sensor demo: the crate falls through the blue zone (sensors detect, they don't push) and lands on the floor.
-Floor:
-Sprite:4931169A6F314FE5
-Position2D:0,-7
-Scale2D:13.6,1
-Collider2D:box,6.8,0.5,0,0,rock
-TriggerZone:
-Sprite:4931169A6F314FE5
-Position2D:0,-2
-Scale2D:8,2
-Tint:0.30,0.60,1,0.35
-Collider2D:box,4,1,0,0,0,sensor
-FallingCrate:
-Sprite:3D94E7A1C5B20F86
-Position2D:0,6
-Velocity2D:0,0
-Collider2D:box,0.5,0.5,0,0,wood
-PhysicsBody2D:1,0,0Joints
-Joint2D:distance|rope|spring,<partnerEntityName>,restLength[,stiffness,damping][,breakForce]Tools
- Windows > Physics lists every collider and body live, with its velocity and whether it is sleeping. Click a row to select it.
- The toolbar's physics freeze and substep buttons pause the solver alone and step it one substep at a time.
- The Scene view's Debug view colours static, dynamic and kinematic shapes.
Current limits
Scripts react to contacts with OnTriggerEnter / OnTriggerExit (a collider with Is sensor
(trigger) ticked) and OnCollisionEnter / OnCollisionExit (solid hits; tick Reports
collisions on one of the two Physics Body 2Ds). ContactOther gives the other entity. Meadow
Quest's coins are triggers. The ImpactAudio2D system plays
impact sounds without any script.