RexPhysics

RexPhysics provide custom raycast-based physics to RexEngine. They’re designed to feel precise, stable, and above all, videogame-y in the most classic way. They allow easy access to acceleration and deceleration, external forces, and single-frame velocity changes. Additionally, they let you walk up and down sloped terrain with no change in speed, reverse or lower gravity, pass through one-way platforms, and more.

Public Methods

public void SetVelocityX(float newVelocity)

Sets the X velocity of the physics.

public void SetVelocityY(float newVelocity)

Sets the Y velocity of the physics.

public void AddVelocityForSingleFrame(Vector2 _velocityToAdd)

Adds velocity to the physics but only for one frame. Calling this multiple times on one frame will cause the effect to stack.

public void FreezeXMovementForSingleFrame()

Freezes all X movement for a single frame.

public void FreezeYMovementForSingleFrame()

Freezes all Y movement for a single frame.

public void FreezeGravityForSingleFrame()

Suppresses gravity for a single frame.

public void ClearSingleFrameVelocity()

Reverts all one-frame velocity added via AddVelocityForSingleFrame to 0.

public void SetAccelerationCapX(float velocityCapX)

If the object is accelerating, this is the highest X speed it can accelerate to.

public void SetAccelerationCapY(float velocityCapY)

If the object is accelerating, this is the highest Y speed it can accelerate to.

public void AddToCollisions(string layerName)

Add a new layer that this object will collide with. Layers added in this manner will stop this object from moving through them, even if their colliders are triggers.

public void RemoveFromCollisions(string layerName)

Removes a layer from the layers this object can collide with. If you remove “Terrain”, it will automatically remove “PassThroughBottom” as well.

public void DisableOneWayPlatforms()

Stops the object from colliding with one-way terrain (the “PassThroughBottom” layer.)

public void EnableOneWayPlatforms()

Enables this object to collide with one-way terrain (the “PassThroughBottom” layer.)

public void AnchorToFloor()

Immediately anchors this object to the closest floor it can collide with.

public void SnapToNearestWall(Direction.Horizontal _direction)

Immediately moves this object against the nearest wall it can collide with in the direction passed in via the _direction argument.

public void SyncGravityScale()

This is called automatically by PhysicsManager when gravityScale is changed; it syncs the gravityScale of this object to the global physics gravity scale.

public float GravityScale()

This returns the gravityScale value of this object.

public string GetSurfaceTag()

Returns the tag for the surface, if any, the actor is currently on top of. Returns null if none.

public bool IsOnSurface()

Returns true if the object is on the floor and gravityScale is normal, OR if the object is on the ceiling and gravityScale is reversed. This is the safest way to detect if the object is on a walkable surface.

public bool DidLandThisFrame()

Returns true if the object landed on walkable terrain this frame.

public bool DidHitCeilingThisFrame()

Returns true if the object bumped into the ceiling on this frame.

public bool DidHitLeftWallThisFrame()

Returns true if this object collided with the left wall this frame.

public bool DidHitRightWallThisFrame()

Returns true if this object collided with the right wall this frame.

public bool DidHitEitherWallThisFrame()

Returns true if this object collided with either the left or the right wall this frame.

public bool IsAgainstEitherWall()

Returns true if this object is currently pressed against either the left or the right wall, regardless of how long they’ve been there.

public void ResetFlags()

Auto-called by PhysicsManager between updates; updates currentProperties and previousProperties to be current for the latest frame.

public void StepPhysics()

Auto-called by PhysicsManager. This method moves the object by its velocity values.

Public Members

public RexObject rexObject

If a RexObject is slotted here, it will receive notifications for various events from this RexPhysics object.

public Gravity gravitySettings

Gravity-related settings for the RexPhysics, including whether gravity is enabled, gravityScale, and maxFallSpeed.

public bool freezeMovementX

If True, this object will not move horizontally.

public bool freezeMovementY

If True, this object will not move vertically.

public bool willSnapToFloorOnStart

If True, this object will snap to the closest floor in Awake().

public Properties properties

The current physics properties of the object, including velocity, acceleration, whether the object is against surfaces, and more. The below public members can be accessed from properties:

public Vector2 velocity
public Vector2 externalVelocity
public Vector2 velocityCap
public Vector2 acceleration
public Vector2 deceleration
public Vector2 externalAcceleration
public Vector2 externalDeceleration
public bool isGrounded
public bool isAgainstCeiling
public bool isAgainstLeftWall
public bool isAgainstRightWall
public bool isFalling
public Vector2 position
public string surfaceTag
public string surfaceLayer
public string wallTag
public float slopeAngle

public Properties previousFrameProperties

The properties of the physics object during the previous frame.

public bool willIgnoreTerrain

If True, this will not collide with the Terrain layer.

public bool isEnabled

Whether or not the RexPhysics will update.