- Home /
The question is answered, right answer was accepted
Problems with collision under certain circumstances.
function OnCollisionEnter(collision: Collision) {
var chrpos=chr.GetComponent.<Rigidbody>();
var posx:float=chrpos.position.x;
var posz:float=chrpos.position.z;
if (collision.gameObject.name == "_CHARACTER"){
if (chrpos.position.y<14){
Debug.Log(chrpos.position.y);
Debug.Log("you got rekt");
chr.GetComponent(character).kill();
gameover.GetComponent(game_over).GameOver();
}
else
{
if (chrpos.position.y<16){chrpos.position=Vector3(posx,16,posz);}
chr.GetComponent(character).grounded();
}
}
}
Don't pay too much attention to the quality of the script as of now because i'm just brainstorming some basic logic. And it works. It works perfectly as long as I have either jumped recently or jumping at the moment. If the character is position.y=14 or above it gets moved up so it gets a bit less frustrating for the player, and all of that works.
However if I leave the player on the ground, he simply warps through the collider, despite being 2 colliders with one rigidbody.
Changing the collision method (Discrete etc) doesn't help at all either. In fact, it works perfectly with all of them except under the circumstances I mentioned.
The collision gets ignored, but if I jump again while inside the collider, it gets the job done aswell. Of course that shouldn't happen as it should have detected it beforehand.
I'm kinda lost as to what to do, to be honest.
I should mention that the character is not moving and the actual moving object is the one without the rigidbody. Could that be the issue? Although it doesnt explain why it's working in the other circumstances then
Of course the problem was the obstacle not having a rigidbody.