GroundCollidedAgainst and Movement Values
Last updated
Last updated
The GroundCollidedAgainst property can be used to detect the type of terrain that a platformer entity is standing on. This property, along with the standard ItemsCollidedAgainst property, can be used to perform complex logic in response to collision after all collision for a frame has been resolved. The most common use of the GroundCollidedAgainst property is to assign movement values.
The GroundCollidedAgainst property is only available for gluj version 22 and newer. For more information see the FileVersion (.gluj) page. New FlatRedBall projects use this version, but some of the samples linked in the Platformer tutorials may not have this value available.
Typically a platformer game will have collision relationships between the Player and various TileShapeCollections. For example, the following screenshot shows collision relationships between the Player and a number of TileShapeCollections.
Whenever the player collides with one of these TileShapeCollections, the GroundCollidedAgainst property will be updated. Some games may have multiple TileShapeCollections represent one type of terrain (such as Ice and IceCloud), so all collision should be resolved before determining the terrain type. In such a situation, the Player entity can have properties for determining the ground type as shown in the following code snippet:
These properties enable the assignment of movement values, such as GroundMovement, in CustomActivity as shown in the following code snippet:
Similar logic could be performed to assign AirMovement and AfterDoubleJump. Consider that the code above requires that the GameScreen has its collision objects exposed publicly. To verify this is the case, select the object in the FlatRedBall Editor and check its HasPublicProperty value.