I am using Unity's Character Controller tool to move my character.
I am using my own movement, gravity, etc, but it seems to be not affecting directly to the movement. I've checked my whole code and reduced it to the minimum just to seek the problem.
I've printed velocity, movement, magnitudes... Everything shows up that the movement it's exactly the same being on a flat surface or on slopes.
I don't know how the Character Controller's script works, so a kind of calculation might being causing that behaviour.
This is how I calculate my movement:
private void SetMovement() {
horizontalMovement = isometricHorizontal * Input.GetAxisRaw(horizontalButton);
verticalMovement = isometricVertical * Input.GetAxisRaw(verticalButton);
movement = (horizontalMovement + verticalMovement).normalized;
MovementModifier();
}
private void MovementModifier() {
if (isSprinting) {
movement.x *= sprintFactor;
movement.z *= sprintFactor;
}
}
private void Move() {
if (movement != Vector3.zero)
characterController.Move(movement * Time.deltaTime * moveSpeed);
}
The velocity down slopes increases at least 30% and is being reduced almost the same when going up.
I would like to keep the same velocity on any surface without needing to apply a movement modificator or reducing it while being over a certain area like slopes or stairs.
EDIT:
This is how I apply gravity.
private void ApplyGravity() {
if (!characterController.isGrounded) {
gravity += Physics.gravity * Time.deltaTime * gravityFactor;
if (gravity.y > 0 && !Input.GetButton(jumpButton) && !isFalling)
gravity += Physics.gravity * Time.deltaTime * gravityFactor * (lowJumpMultiplier - 1);
}
else if (!isJumping) gravity = Vector3.down;
CheckCollisionFlags();
movement += gravity;
}
private void CheckCollisionFlags() {
switch (characterController.collisionFlags) {
case UnityEngine.CollisionFlags.Above:
gravity = Vector3.down;
break;
}
}