TerrainCollisionPiece

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Game.Graphics.Worlds.TerrainPatch, Libraries.Game.Graphics.Model, Libraries.Game.Graphics.Worlds.Terrain, Libraries.Interface.Item3D, Libraries.Interface.Item, Libraries.Language.Object

A TerrainCollisionPiece is a small square of ground that the physics engine can collide with, but that is never drawn. A TerrainCollision keeps a few of them near the player, and moves them as the player moves, so only the ground nearby costs anything in physics. It is a TerrainPatch with no mesh, kept hidden. Its collision shape reads the heights straight from the TerrainData. This matches the collision shapes Terrain3DCollision makes in its dynamic mode, which are 16 samples across by default.

Example Code

use Libraries.Game.Graphics.Worlds.TerrainData
use Libraries.Game.Graphics.Worlds.TerrainCollisionPiece

TerrainData data
data:AddRegion(0, 0)
TerrainCollisionPiece piece
piece:Place(data, 32, 48, 16)

Actions

Covers(integer firstX, integer firstZ)

This action returns true if the piece covers the square starting at a sample.

Parameters

  • firstX integer: The square's first sample along x.
  • firstZ integer: The square's first sample along z.

Returns

boolean: True if the piece starts at that sample.

Place(Libraries.Game.Graphics.Worlds.TerrainData data, integer firstX, integer firstZ, integer size)

This action moves the piece to cover a square of samples, and gives it the collision shape for the ground there. Physics settings, such as friction, are kept. A piece that is in a game should be removed from it before being placed, and added again after, so the physics engine sees its new shape and position.

Parameters

  • data Libraries.Game.Graphics.Worlds.TerrainData: The heights of the whole terrain.
  • firstX integer: The square's first sample along x.
  • firstZ integer: The square's first sample along z.
  • size integer: How many cells the square covers along each side.

Inherited Actions

110 actions from Libraries.Game.Graphics.Model
14 actions from Libraries.Game.Graphics.Worlds.Terrain
13 actions from Libraries.Game.Graphics.Worlds.TerrainPatch
62 actions from Libraries.Interface.Item
211 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object