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 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 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 isMovingPlatform
If True, other RexPhysics objects can ride on top of this.
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.
public Properties previousFrameProperties
The properties of the physics object during the previous frame.
public bool willStickToMovingPlatforms
Whether or not the object can ride on moving platforms.
public MovingPlatform movingPlatform
The moving platform this is riding, if any.
public bool willIgnoreTerrain
If True, this will not collide with the Terrain layer.
public bool isEnabled
Whether or not the RexPhysics will update.