PlayerMover Abstract Class

public abstract class PlayerMover : MonoBehaviour

Provides a base implementation for Player Movers.

Player Movers are used anytime S.A.M. needs to move the Player, for instance when the Active Grid is moved in response to an Origin Cell Change(and Move Player After Origin Cell Change is enabeld on Active Grid), or when the TryMovePlayerToLocation method is called.

If no PlayerMover is provided to the Active Grid, the player will be moved by simply calling Player.Position = newPosition, or Player.Position += adjustment (the latter is used when an Origin Cell Change occurs). Depending on your movement system, however, this may not be ideal, as it can de-sync the player from the physics system and cause issues (such as the player falling through the world).

For this reason, you can create a custom script or modify an existing script to derive from PlayerMover and implement the required methods in a way that works with your movement scheme.

In order to save the player's position correctly, the Active Grid needs to know exactly when the player's position has been changed by your implementation. As such, it is imperative that once you move the player, you break out of or complete the coroutine so that the script using the PlayerMover can continue executing.

Also note that for Origin Cell changes, you also have the options of letting your World Shifter (if using one) move the player, which in many instances will be better as you can time the move with the movement of the Asset Chunks surrounding the player, so that they don't notice the move. If you go this route, you should disable Move Player After Origin Cell Change on your Active Grid.

Methods

MovePlayerByAmount(IPlayer, Vector3Double)

public abstract IEnumerator<YieldInstruction> MovePlayerByAmount(IPlayer player, Vector3Double amountToMovePlayer, bool immediateMode)

When override in a derived class, moves the player by the Vector3Double amount. That is, the amountToMovePlayer should be added to the existing player's position.

Parameters

Name Type Description
player IPlayer

The player that will be moved.

amountToMovePlayer Vector3Double

The amount the player will be moved (the amount to add to the player's Current position).

immediateMode

A value of true indicates that the method is being run in immediate mode, meaning the code must be able to run fully without yielding. Your code can contain yield statements, however they will be skipped over, thus it is usually better to write alternative code that only runs in immediate mode that works without yielding. If your code depends on yielding it will almost certainly stall (which will stall out the calling method).

Note that currently immediateMode is only used by WorldShifter's when the 'Perform Shift In Single Frame' setting is enabled, so if you truly cannot implement code that works for it, you will need to not use a World Shifter with that setting enabled.

Returns

IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine. See the YieldInstruction page for more info.


MovePlayerToPosition(IPlayer, Vector3Double, bool)

public abstract IEnumerator<YieldInstruction> MovePlayerToPosition(IPlayer player, Vector3Double position, bool immediateMode)

When override in a derived class, moves the player to the specified position in world space.

Parameters

Name Type Description
player IPlayer

The player that will be moved.

position Vector3Double

The position the player will be moved to.

immediateMode

A value of true indicates that the method is being run in immediate mode, meaning the code must be able to run fully without yielding. Your code can contain yield statements, however they will be skipped over, thus it is usually better to write alternative code that only runs in immediate mode that works without yielding. If your code depends on yielding it will almost certainly stall (which will stall out the calling method).

Note that currently immediateMode is not used by any SAM related code for MovePlayerToPosition (but it is used with MovePlayerByAmount), so you can technically ignore this setting for now.

Returns

IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine. See the YieldInstruction page for more info.