Touches - theRAPTLab/gsgo GitHub Wiki
See !93 !89 !106 !116
[[TOC]]
If you want to use touches
, you need to use the Physics feature:
- Define
Costume
and set the default sprite BEFORE using Physics - Use Physics on both the source and target blueprints you want to monitor.
- Use Touches on the blueprint that will be running the touch test, and register the agents you want to monitor. (You don't need to use Touches on the target blueprint).
- Physics will automatically define the physics body bounds based on the Costume size.
- If you want to change the size of the character, set size / scale via Physics so the system can maintain both the visual size and the physics body size.
- Touches are processed based on the Physics body size. So you can potentially have a physics body and sprite costume size that are independent of each other.
- In general, don't use the following agent props directly:
scale
scaleY
This is a simpler and more efficient version of Touches that adds support for different types of touches.
-
There are three types of touches:
- c2c -- Center to Center
- c2b -- Center to Bounds
- b2b -- Bounds to Bounds
-
These correspond to new conditions tests:
- c2c --> centerTouchesCenter
- c2b --> centerTouches
- b2b --> touches
-
Each condition test also has a 'firstTouches' and 'lastTouches' variant.
-
It hooks into SIM/AGENTS_UPDATE phase instead of using a rxjs interval timer REVIEW: We're using AGENTS_UPDATE so it doesn't run during PRERUN We might need a new phase or something that only runs when the simulation is running and NOT during PRERUN. It also needs to run BEFORE CONDITIONS_UPDATE, since the conditions tests rely on the calculations.
-
Most calculations are done during the update loop.
-
The touch information is saved into agent. -- agent.lastTouch -- touch info from the previous frame -- agent.isTouching -- touch info from the current frame
-
lastTouch/isTouching are dictionaries, keyed to the target id whose values are the frame number of the detected touch types. e.g.:
agent.lastTouched[501] = { c2c: 1534920, c2b: undefined, b2b: undefined }
-
There no feature properties. The data is stored in agent.
-
There are essentially no methods other than 'monitor'. Use conditions tests.
The key steps:
- You have to register the type of touch you want to monitor.
- Use the corresponding condition test
Example:
useFeature Physics
useFeature Touches
featCall Touches monitor Algae b2b
when Fish touches Algae [[ ... ]]
- Physics Feature
# PROGRAM DEFINE
useFeature Costume
featCall Costume setCostume 'fish.json' 0
useFeature Physics
useFeature Touches
featCall Touches monitorTouchesWith Algae
# PROGRAM UPDATE
when Fish touches Algae [[
every 1 runAtStart [[
prop Fish.energyLevel add 10
prop Algae.energyLevel sub 10
featCall Fish.Costume setGlow 0.5
]]
]]
- touching physics body boundaries vs touching centers
See Conditions
See Conditions
featCall Touches getTouchingAgent <touchType>
will return the first agent that passes the <touchType>
type test relative to this agent.
TouchTypes include:
-
c2c
-- center to center -
c2b
-- center to bounds -
b2b
-- bounds to bounds (any edge touching another edge) -
binb
-- bounds in bounds (first agent inside second agent)
This is primarily used by Vision's m_IsTargetColorVisible
call to get the background agent of the target.