Physics issues in 2.5D platformer

Hello,
I marked this as a physics issue, but I’m not positive that’s where the problem lies. Please forgive me if this is posted in the wrong place.

I’m running into a strange bug when play testing my player movement script. Currently, the player can run right/left, jump, and when the player jumps into a wall, they enter a “wall slide” where their vertical velocity is reduced to -1 so they very slowly slide down the wall until they either A) hit the jump button, resulting in a vault away from the wall, or B) hit the “s” key, which exits the wall slide. However, if there is a wall floating in the air, and the player slides all the way to the bottom of the wall, right as the top edge of the player’s box collider meets the bottom edge of the floating wall, the player gets flung beneath the wall.

Anyone know why this could be happening?



In the attached image, the blue represents what I want it to do, upon reaching the bottom edge of the wall. The red is what it currently does, for some reason or another.

I’ll post my code here for reference.

using UnityEngine;
using System.Collections;

public class PlayerMotor : MonoBehaviour
{
    //Variables
    private Vector3 moveVector;
    private Vector3 lastMove;
    public float speed = 8;
    public float jumpForce = 12;
    public float gravity = 25;
    private float verticalVelocity;
    private CharacterController controller;

    private void Start()
    {
        //Get Character Controller
        controller = GetComponent<CharacterController> ();
    }

    private void Update()
    {
    
        //Set movement vectors
        moveVector = Vector3.zero;
        moveVector.x = Input.GetAxis ("Horizontal") * speed;

        //Apply jump if controller is on the ground
        if (controller.isGrounded)
        {
            verticalVelocity = -1;

            if (Input.GetKeyDown (KeyCode.Space))
            {
                verticalVelocity = jumpForce;
            }
        }
        else
        {
            //Disable movement while in mid air
            verticalVelocity -= gravity * Time.deltaTime;
            moveVector = lastMove;
        }

        moveVector.y = 0;
        moveVector.Normalize();
        moveVector *= speed;
        moveVector.y = verticalVelocity;

        //Move player
        controller.Move (moveVector * Time.deltaTime);
        lastMove = moveVector;
    }

    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        //Detect if controller has jumped into a wall
        if (!controller.isGrounded && hit.normal.y < 0.01f) {

            //Apply wall slide
            verticalVelocity = -1;
 

            //Apply wall jump
            if (Input.GetKeyDown (KeyCode.Space)) {
                verticalVelocity = jumpForce;
                moveVector = hit.normal * speed;
            }
            
            //Exit wall slide
            if (Input.GetKeyDown (KeyCode.S)) {
                verticalVelocity = 0;
                moveVector.x = hit.normal.y;
            }
            
        } else
            return;

    }
    
}

Okay.
Do you have a trigger/collider, on the lower platform, that the red arrow
is pointing too? If so…

It’s possible, that the trigger/collider (if there is one), on the lower platform
might be a bit too wide, or the same size, as the lower platform.
So when your character touches it, the game engine thinks, that you want
to land, on that lower platform. That could explain, why you character
gets pitched onto it.

If the trigger/collider, is the same size and width as the lower platform…
My suggestion would be, to move that lower platform, a bit to the left,
away from being under, the wall above it. Then try to do, the wall slide
thing and see what happens from there.

Or, (if the trigger/collider is too wide), reduce the width size, of the
trigger/collider and then (if you want) move the lower platform, a bit
to the left, away from being under, the wall above it and see what happens
from there.