I have a 3D character with a Rigidbody, and his only movement is sliding through walls (without gravity envolved) but most of the times, once it jumps from one wall to another, it collides by 1 pixel.
In the image, the player went from corner right to left, and went back from left to right, but stopped in the start of the wall before getting into the corner.
Movement code (just in case):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMovement : MonoBehaviour
{
private Rigidbody _rbody;
public float movementSpeed = 5f;
private Vector3 _directionalInput;
private bool IsMoving => _rbody.velocity != Vector3.zero;
private Vector3 _queueMovement = Vector3.zero;
[SerializeField] private float queueMovementCooldown = 0.15f;
private float _queueMovementTimer;
private void Awake()
{
_queueMovementTimer = 0;
_rbody = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
float xInput = Input.GetAxisRaw("Horizontal");
float yInput = Input.GetAxisRaw("Vertical");
yInput = xInput != 0 ? 0 : yInput;
_directionalInput = new Vector3(xInput, yInput, 0);
if (!IsMoving)
{
_rbody.velocity = Vector3.zero;
if (_queueMovement != Vector3.zero)
{
Move(_queueMovement);
}
else
{
Move(_directionalInput);
}
}
else
{
if (_rbody.velocity.magnitude < movementSpeed) _rbody.velocity = Vector3.zero;
if (queueMovementCooldown > _queueMovementTimer)
{
_queueMovement = _directionalInput;
_queueMovementTimer += Time.deltaTime;
}
else
{
_queueMovement = Vector3.zero;
}
}
}
private void Move(Vector3 direction)
{
_rbody.velocity = direction * movementSpeed;
}
private void OnDrawGizmos()
{
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, transform.position + _directionalInput);
Gizmos.color = Color.yellow;
Gizmos.DrawLine(transform.position, transform.position + _queueMovement);
}
}