- Home /
How to handle custom collision sliding
So, I need to create my own custom character controller. It's for a minecraft starter/template project I'm working on. I've gotten a ways into it, and realized that using a mesh collider for the terrain isn't the best way to go. Easier...yeah, for now.
Anyway...basically, if you'eve never played or heard of minecraft, welcome to Earth! It's a game where a player lives in a world made up of cubes.
So, basically I just need the player to stop moving when he hits a cube.
I've got the simple stuff here, with forward and backwards movement.
private void Update() { Vector3 position = transform.position; m_Velocity = Vector3.zero; m_Forward = transform.forward;
if (Input.inputString.Contains("w"))
{
m_Velocity = m_Forward;
}
else if (Input.inputString.Contains("s"))
{
m_Velocity = -m_Forward;
}
m_Velocity += m_Gravity;
transform.position += m_Velocity;
}
But...I'm not sure how to negate movement along a particular axis, depending on which direction the player is moving. If the player hits a cube at an angle, I just want him to slide along the edge, and not bring all movement to a halt. Does this make any sense? Since all collisions (for now) are with cubes, I can just check the world data to see if the player is about to enter a solid cube, and react accordingly.
Hope that makes sense.