Skip to content

Body

namespace Griff.Scenes;
public sealed class Body : Component

Makes an entity with a Collider move under velocity and gravity and collide with solids. On an isometric Tilemap, it meets the solid diamonds with the diamond under its collider (as wide as the collider, half as tall, round its middle) and slides along them; on a hex one, its collider meets the solid hexagons’ six sides and slides along them. With Rotates on, it turns too: knocked off its middle it spins, it tips over edges and falls flat, and its box or polygon collider turns with it.

This is a component: its saved properties are on its component page.

public float AirTime { get; }

Seconds since the body last stood on something: 0 while it’s grounded.

public bool Asleep { get; set; }

True while it’s asleep: once it and every body that turns touching it have been still for half a second, they fall asleep together and stay exactly where they are, costing a fraction of what they did, until something disturbs them: a hit, a push, its Velocity or Spin set, something pushed into it, or what holds it up moving or going. Tick it to start it asleep, so a tower built resting on itself stands until something knocks it; untick it to wake it. Only one that Rotates sleeps.

public float Bounciness { get; set; }

How much speed is kept when hitting something: 0 stops dead (the default), 1 bounces back as fast as it hit. Slow bounces settle to a stop, so a bouncing ball comes to rest.

public Vector2 CenterOfMass { get; }

What it turns round: its collider’s middle in the world (where a polygon balances), or its position without a collider.

public float Friction { get; set; }

How quickly it stops sliding along the ground, in world units per second lost each second: a crate shoved or thrown comes to rest instead of gliding on. 0 (the default) keeps sliding; movement components steer bodies themselves either way.

public bool Frozen { get; set; }

Holds it still where it is, like a wall: it doesn’t fall or move, and other bodies bump into it. Untick it (or grab it with the Sandbox Tools) and it moves again. Welded to it, a whole contraption holds still.

public float GravityScale { get; set; }

Multiplier on world gravity. 0 for top-down games or floating things.

public float Grip { get; set; }

How well it grips what it touches as it turns, from 0 (ice: it slides off an edge rather than tipping over it) to 1 (it hardly ever slips). Sliding along something it grips slows it, and turns it.

public Entity? Ground { get; }

What the body is standing on (a platform, the floor’s tilemap), or null in the air. When that moves, the body rides along with it, so platforms moved by scripts or tweens carry whoever is on them.

public float Height { get; }

How high it is: its entity’s height in the world.

public bool HeldStill { get; }

Held still for the step: frozen, or paused with its group (see IsPaused). Others bump into it as into a wall.

public float Inertia { get; }

How hard it is to turn (its moment of inertia), from its Mass and its collider’s size: a long plank turns more slowly than a small crate of the same weight.

public bool IsDroppingThrough { get; }

True while the body falls through one-way platforms (see DropThrough).

public bool IsGrounded { get; }

True if the body rested on something below it during the last physics step.

public float Mass { get; set; }

How heavy it is, for pushes from a Thruster and for sharing movement with what it’s welded or roped to: a heavy crate drags a light balloon down, a light one is lifted. 1 is a crate. Bodies that rotate share their knocks by it too: a heavy ball bowls a light plank over.

public float RollingResistance { get; set; }

How much a round one (a CircleCollider) is slowed as it rolls, so a ball comes to rest: 0 rolls on and on, 0.1 (the default) stops a ball rolling at 5 units a second in about 3 seconds, and 1 hardly rolls at all. It rests on a slope up to about this steep (rise over run). With no gravity on it (a top-down game, Gravity Scale 0) it rolls on the ground under the view and slows the same way; set it to 0 for one floating in space.

public bool Rotates { get; set; }

Lets it turn: hit or pushed off its middle it spins (see Spin), it tips over edges and falls flat, and its box or polygon collider turns with the entity, so others meet it turned. Off (the default), it stays upright whatever hits it, as players and enemies should, and so does its box. Welded to others, they turn as one if they all rotate; hung on a HingeJoint without it, it hangs upright.

public float Speed { get; }

How fast it’s going, in world units per second, whichever way.

public float Spin { get; set; }

How fast it turns, in degrees per second: positive turns anticlockwise. Set it to start it spinning.

public float StillFor { get; set; }

Seconds it has been all but still (see Asleep): at half a second, and every body that turns touching it with it, it falls asleep. The game counts it.

public Vector2 Velocity { get; set; }

World units per second.

public int WallSide { get; }

-1 if a wall stopped the body moving left during the last physics step, 1 if one stopped it moving right, else 0: for wall jumps and slides, or turning round.

public void DropThrough(float seconds = 0.25f)

Falls through the one-way platforms it’s standing on (and any it meets) for seconds: down and Jump on a platform. if (Input.Vertical < -0.5f && Input.WasPressed("Jump")) body.DropThrough();

public void Float()

For the next physics step only: no gravity (climbing, dashing, top-down, a tractor beam’s pull), and passing through one-way platforms (climbing a ladder through one). What floats it does so again each step.

public void Push(Vector2 force, float seconds)

Applies a push for one step: force divided by its Mass, over seconds.

public void PushAt(Vector2 force, Vector2 point, float seconds)

Pushes it at point in the world, as Push does; one that Rotates also turns, the more the further from its middle the push is (a kick to a plank’s end spins it). body.PushAt(new Vector2(20, 0), corner, Time.Delta);

public void Twist(float torque, float seconds)

Turns it for one step with a torque (a twisting push, positive anticlockwise) over seconds: its Spin changes by the torque divided by its Inertia. Only one that Rotates turns. body.Twist(-Input.Horizontal * 20, Time.Delta);

public bool WasGrounded(float seconds)

True while grounded, and for seconds after walking off an edge (but not after jumping): coyote time, so a jump pressed a moment too late still happens. if (body.WasGrounded(0.1f) && Input.WasPressed("Jump"))