- Home /
Cannot register Collision from behind.
Hey there, I got a small problem: I am currently working on an enemy script for my 2D Game. While most of it works fine, I cannot detect the collision between my character controller and my rigidbody, when the character controller hits the rigid body from behind. to be more specific, rigid body moves to the right, character controller stands right hand side of it or moves to the left --> collision.
Rigidbody moves to the right, character controller stands left hand side and runs into the collider ( both moving to the right now) no collision....
function OnCollisionEnter(collision : Collision) {
var contact : ContactPoint = collision.contacts[0];
var pos : Vector2 = contact.point;
if (collision.gameObject.name !="AvestasDummy"){
if(pos.x>transform.position.x && pos.y>transform.position.y-(0.5*transform.localScale.y-0.1) && facesRight){
currentSpeed=currentSpeed*-1;
facesRight=false;
}
if(pos.x<transform.position.x && pos.y>transform.position.y-(0.5*transform.localScale.y-0.1) && !facesRight){
currentSpeed=currentSpeed*-1;
facesRight=true;
}
}
else{
if(pos.x>transform.position.x && pos.y>transform.position.y-(0.5*transform.localScale.y-0.1) && !Gesammelt.gotDmg){
if((!dmgFromBack && facesRight) || dmgFromBack){
Gesammelt.avestasLife-=1;
moving2.knockBackRechts=true;
}
}
if(pos.x<transform.position.x && pos.y>transform.position.y-(0.5*transform.localScale.y-0.1) && !Gesammelt.gotDmg){
if((!dmgFromBack && !facesRight) || dmgFromBack){
Gesammelt.avestasLife-=1;
moving2.knockBackLinks=true;
}
}
}
}
the characterController's name is "AvestasDummy"
Anyone got an idea? :)
OnCollisionEnter occurs when the Rigidbody hits the CharacterController, but not when the CharacterController hits the Rigidbody - could be this the case?
Yes, I am using a box collider on the rigid body
@aldonaletto: Yeah, I think this might be the case, but I thought it would work, because both objects are moving, I am not really in the collision materia :S
Your answer
Follow this Question
Related Questions
Physics goes crazy when rigidbody collides with moving character controller 0 Answers
Limiting rigidbody physics influence on another rigidbody 0 Answers
How to setup character Collisions? 2 Answers
Character Controller with rigidbody 2 Answers
CharacterController jumps when colliding with kinematic rigidbodies 1 Answer