wordplaydev / wordplay

An accessible, language-inclusive programming language and IDE for creating interactive typography on the web.
Other
60 stars 22 forks source link

Collisions don't work for content not in motion #407

Closed amyjko closed 7 months ago

amyjko commented 7 months ago

Expected behavior

In a project with content whose places are set directly, rather than by Motion, collisions should still fire:

collision: Collision()

Stage([
  Phrase('hi' name: 'hi' place: Placement() matter: Matter(1kg))
  Phrase('collide' name: 'hey' place: Place(0m 2m) matter: Matter(1kg))
  Phrase(collision → '' place: Place(0m -2m))
])

When hi is moved to intersect with hey, there should be a collision event.

Actual behavior

There's no collision event when hi intersects.

Fix

The root cause of this is that the Physics engine is only updated if the Evaluator.addStreamFor() detects a TemporalStreamValue. Only when it does does ticking occur, physics are update, and collisions are triggered. Adding a Time() stream to the above example makes it work.

The solution to this is to update the physics engine after each re-evaluation reaction if there won't be a tick. That way, position changes will cause collisions too, even if there's no temporal stream.

amyjko commented 7 months ago

Fixed in 82239ffec.