Skip to content

HingeJoint

namespace Griff.Scenes;
public sealed class HingeJoint : Component

Pins its Body to another body (To), or to a point in the world, at one point (its Anchor), so it turns there: a wheel on a cart, a door, a flipper, a seesaw, a windmill. It can be kept within a range of angles (Limit) and turned by a motor (Motor), and the two it joins don’t bump into each other unless Collide is ticked. Tick Rotates on the body for it to swing round (Entity > Add Hinge does); without it, it hangs upright from the hinge, as a Ferris wheel’s seats do. What it’s hinged to turns with it if that rotates too, and is pulled about by it if it moves under physics; anything else (a player, a wall, a platform moved by a script) just carries the hinge along.

The two are joined as they stand when the game starts (see Joined): the hinge stays at that point on each of them, and its angles count from how they’re turned then. In the Scene view, drag the hinge’s knob to move it and the ends of its arc to set its limits.

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

public Vector2 Anchor { get; set; }

Where the hinge is on this entity, from its position, in its own units (before its scale, turned with it): (0, 0) is its middle, as a wheel’s; (-2, 0) one end of a plank 4 long, as a door’s.

public float Angle { get; }

How far it has turned on the hinge from how it started, in degrees (positive anticlockwise), against what it’s hinged to: from -180 to 180.

public bool Collide { get; set; }

Let the two it joins bump into each other. Off (the default), they pass through each other where they meet.

public float Friction { get; set; }

How stiffly it turns, from 0 (it swings on and on) to 1 (a stiff hinge that stops a swinging door soon, a little off straight down): the more weight on it, the harder it is to turn. The default, 0.05, lets wheels roll on and slows a pendulum over a while. A running Motor takes no notice of it.

public bool Joined { get; set; }

True once the game has joined the two as they stood (it sets OtherAnchor and StartAngle). Untick it to join them again as they are now, where Anchor is.

public bool Limit { get; set; }

Keep it within LowerAngle and UpperAngle: a door that opens one way, a flipper.

public float LowerAngle { get; set; }

How far it can turn clockwise (negative) from how it started, in degrees, as far as -180 (half a turn).

public bool Motor { get; set; }

Turn it with a motor, at MotorSpeed as far as MotorStrength lets it: a wheel that drives a cart, a windmill. A switch or a wire into its “Power” turns the motor on and off (a flipper on a button).

public float MotorSpeed { get; set; }

How fast the motor turns it, in degrees a second: positive turns it anticlockwise.

public float MotorStrength { get; set; }

How hard the motor can turn it (the most torque it has): 100 turns a crate at full speed in an instant, and lifts a plank 4 long by its end; a heavy load turns more slowly or stalls.

public Vector2 OtherAnchor { get; set; }

Where the hinge is on what it’s hinged to, from its position in its own units (or, hinged to the world, where it is in the world): the game sets it as it joins them.

public Entity? OtherEntity { get; }

What it’s hinged to (see To), or null for the world.

public float StartAngle { get; set; }

How the two were turned against each other as they were joined, in degrees: the game sets it.

public string? To { get; set; }

What it’s hinged to, by name: the nearest entity called that. Empty pins it to the world, where the hinge is when the game starts.

public float UpperAngle { get; set; }

How far it can turn anticlockwise (positive) from how it started, in degrees, as far as 180 (half a turn).

public Vector2 WorldAnchor { get; }

Where the hinge is in the world.

public void HingeTo(Entity? other)

Hinges it to other (null: the world), that one even if others share its name.

public static Entity? Nearest(Scene scene, Entity from, string name)

The entity called name nearest from (not itself), for a part that wants the nearest.

public void Reverse()

Turns the motor the other way.