CharacterController.Move isn't setting collision flags
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);
Answer by MeteoricDragon · Aug 27, 2018 at 12:31 AM
I found out that the Controller's intrinsic CollisionFlags are being set properly, but the return type is not.
Your answer
Follow this Question
Related Questions
MoveTowards is curving for no reason 0 Answers
How to make character look at movement direction? 1 Answer
2D plaformer, Can bug me into wall 2 Answers
How can I adapt this character controller movement script to allow movement in mid air? 0 Answers
How do i move a cube like an actual cube?,How Can i Move a Cube? 0 Answers