- Home /
Collision Issue - Walk Through Object
Hello,
I've been working on a top down shooter game for sometime now, and I've always had this problem where I can walk through colliders by 'rubbing' against them, side to side.
So initially, if I run into a wall (for example), yes, it will stop me. But as I said, moving the character side to side of the wall, will eventually pop me through to the other side.
I don't know what the issue here is. Let me explain what I have:
Player:
Rigidbody (Is Kinematic, Frozen all constrains, Interpolate, Continuous detection)
Character Controller
Capsule Collider (Slightly larger radius than Character Controller)
Collider Object
Box Collider
Player Scripts (Movement):
Basically, the character will always face towards the position of the mouse. By pressing W will always move it towards the MOUSE.
function Update(){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var playerRotateSpeed = 10;
var hitdist = 0.0;
var targetPoint = ray.GetPoint(hitdist);
var lookPos = targetPoint - transform.position;
lookPos.y = 0;
if(canMove){
var targetRotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, playerRotateSpeed * Time.deltaTime);
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
directionVector = transform.rotation * directionVector * walkingSpeed;
motor.inputMoveDirection = directionVector;
}
transform.position.y = 2.76011;
}
Now I have a feeling that this script is actually causing the issue? The character will still continue to walk even if there is a collider in its way. Right? Or is it something else?
FYI - On very small occasions, the character will just walk straight through a collider without any struggle, as if it wasn't even there.
Thanks.
You are effectively mixing movement thru the physics engine with directly setting transform values.
"transform.position.y = 2.76011;"
I assume this is what is causing you problems. If you need to restrict the y position, you could place a configurable joint on the character and tie it to the world pos of y=2.76011.
Would it be better moving my rigidbody, rather than the transform then?