I have a simple setup. A player with a camera, a plane that the player walks on, and two walls with box colliders.
THE PROBLEM When moving in one direction (X or Z-Axis), the player stops when touching the wall. But in the corner where the two walls intersect, when moving diagonally with W and D keys for example, the player moves through or slips through. How can I prevent this, as I have been struggling with it for some time.
Below is my Character Controller Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
public float p_moveSpeed = 10f;
void Start()
{
}
void Update()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 moveDirection = new Vector3(horizontalInput, 0f, verticalInput);
transform.position += moveDirection * p_moveSpeed * Time.deltaTime;
moveDirection.Normalize();
}
void LateUpdate()
{
Vector3 position = transform.position;
transform.position = position;
}
}
Below are the screenshots I took where I was against the wall, another screenshot where I got through the two walls intersecting and keep in mind both walls have a box collider on it.
Here I am pressed against the wall, walking straight into it...
The INSPECTOR properties of the cube which acts as my wall...
The INSPECTOR Properties of my capsule player...
It is as if my player walks through the intersection, how I am able to rectify it, I do not know. For those willing to assist, thank you in advance. I have watched numerous videos and tutorials about collision but not once have I seen something like this where the player is able to stop when colliding into the wall but goes through at the intersection walls (with colliders attached)...
- I have tried putting spheres in the corner with a collider.
- I have tried making both my walls STATIC in the HIERARCHY.
- I have tried setting both walls as KINEMATIC
- I have tried using every collider possible.
- I have tried adding more Rigidbodies.
- With the Rigidbodies, I changed the COLLISION DETECTION various times but was unsuccessful.
- I have tried resizing my player and my walls but nothing happened, still the same problem.
LateUpdatesupposed to do...? In general if you want to use physics then you shouldn't move your object viatransformbut ratherRigidbody...