Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

I used it to create the game mechanic where the player can only go through the tiny gaps sideways. 

I tried using character controller for the player movement at first but it only uses capsule colliders for the player collision. I tried the standard starter asset but ultimately decided to make my own player controller with rigid-body physics which I admit is not as smooth/good.

(3 edits) (+1)

Interesting, you could get into a myriad of problems later on though. I don't know your particular setup, but you could adjust the height and with of the collider, when you need him to go through tiny gaps. 

I'm trying to play it again now, but it's better to adjust now, and do it properly, because it will give you headaches later on, when you work on bigger games. Maybe this can help you?

Try if it works for your Project.

It adjust your characters capsule collider by half or whatever you put into the inspector, that should give you an idea, how you could make it work to get through tiny spaces.
 

using UnityEngine;  
public class CharacterColliderControl : MonoBehaviour
{     
[SerializeField] private CapsuleCollider characterCollider;     
[SerializeField] private float normalHeight = 2f;     
[SerializeField] private float crouchHeight = 1f;     
[SerializeField] private Vector3 normalCenter;     
[SerializeField] private Vector3 crouchCenter;      
private bool isCrouching = false;      
void Start()     
{         
if (characterCollider == null)         
{             
characterCollider = GetComponent<capsulecollider>();  
}       
if (normalCenter == Vector3.zero) normalCenter = characterCollider.center;         
if (crouchCenter == Vector3.zero) crouchCenter = normalCenter / 2;    
}      
void Update()     
{         
if (Input.GetKeyDown(KeyCode.C))         
{             
isCrouching = !isCrouching;              
if (isCrouching)             
{                 
characterCollider.height = crouchHeight;
characterCollider.center = crouchCenter;
}            
else             
{                 
characterCollider.height = normalHeight;
characterCollider.center = normalCenter;   
}         
}     
} 
}
(+1)

I am pretty much doing that same thing but with a box collider + I lerp the collider size for smoother transition.

By moving through tiny gaps, I meant the mechanic where the player can go through the tiny gaps by strafing sideways. Capsule has a fixed radius so it won't matter if the player is facing straight or sideways.

I won't use such methods in my future games. It was just a unique scenario and I was doing a bit of experimentation with player movement.  I have used character controller in my previous games, just this one is an exception.

Anyway thanks for the feedbacks and suggestion. I appreciate it.