I have a function in a “LevitateMotor” class that levitates or swims my CharacterController. It is supposed to set a CollisionFlags variable by invoking CharacterController.Move method. But for some reason, no collisionFlags
are set after the CharacterController moves and collides with walls. The character is being stopped by the walls but no CollisionFlag changes occur. Is there some limitation to the Move method I don’t know about?
The very same CharacterController uses a different “GroundMotor” class to make the character walk on the ground, and the collisionFlags variable in that class changes correctly according to what it collides with.
playerMotor.controller
is the CharacterController, Look towards the bottom of the method below to find the collisionFlags assignment.
// this is the member-level declaration reference to PlayerMotor inside LevitateMotor class
public PlayerMotor playerMotor;
// PlayerMotor is initialized like this in the Start method
playerMotor = GetComponent<PlayerMotor>();
void Move(Vector3 direction, bool upOrDown = false)
{
if (playerSwimming)
{
// Do not allow player to swim up out of water, as he would immediately be pulled back in, making jerky movement and playing the splash sound repeatedly
if ((direction.y > 0) && (playerMotor.controller.transform.position.y + (50 * MeshReader.GlobalScale) - 0.93f) >=
(GameManager.Instance.PlayerEnterExit.blockWaterLevel * -1 * MeshReader.GlobalScale) &&
!playerLevitating)
direction.y = 0;
Entity.PlayerEntity player = GameManager.Instance.PlayerEntity;
float baseSpeed = speedChanger.GetBaseSpeed();
moveSpeed = speedChanger.GetSwimSpeed(baseSpeed);
}
// There's a fixed speed for up/down movement
if (upOrDown)
moveSpeed = 80f / PlayerSpeedChanger.classicToUnitySpeedUnitRatio;
collisionFlags = playerMotor.controller.Move(direction * moveSpeed * Time.deltaTime);
// Reset to levitate speed in case it has been changed by swimming
moveSpeed = 4.0f;
}
Below is the assignment statement in the GroundMotor class that assigns to collisionFlags correctly. And the CharacterController moves properly too.
// this is the member level CharacterController declaration
private CharacterController controller;
// Initialized in start method
controller = GetComponent<CharacterController>();
// Called to move the controller via walking
collisionFlags = controller.Move(moveDirection * Time.deltaTime);