- Home /
Car smashing through crowd- Collision issue.
Hey guys! I've got a car to launch into a crowd. Currently it hits robots and they tumble and die when hit. I need the car to continue through the crowd without stopping and smash into a wall. Car contacting robots should cause ROBOTS to die. Car contacting wall should cause CAR to die.
I'm currently using OnCollisionEnter with code to kill the robots and car on impact. If car is not killed with code, it just bounces around level after hitting robot.
What would be the best way to use either OnCollisionEnter or OnTriggerEnter with seperate tags for "Enemy" and "Wall" to dictate end results?
I'm using JavaScript too, Thanks for any advice.
Main code block attached to EnemyRobot:
function OnCollisionEnter (collisionInfo : Collision)
// Used if we were hit by a CAR on left or right side...
{
var hitDir : Vector3 = collisionInfo.contacts[0].point - transform.position;
var left : Vector3 = transform.TransformDirection( Vector3.left );
//var right : Vector3 = transform.TransformDirection( Vector3.right );
if( Vector3.Dot( left, hitDir ) > 0)
{
TumbleRight();
Debug.Log("HitLeft");
//We were hit on the Left, Play the TUMBLE RIGHT animation
}
else
{
TumbleLeft();
Debug.Log("HitRight");
//We were hit on the Right, Play the TUMBLE LEFT animation
}
}
Main code block attaced to Car:
function OnCollisionEnter (collision : Collision) { // Instantiate explosion at the impact point and rotate the explosion // so that the y-axis faces along the surface normal var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal); Instantiate (explosion, contact.point, rotation);
// And kill our selves
Kill ();
}
Answer by spinaljack · May 07, 2010 at 07:17 AM
You can try increasing the car's rigidbody mass and lowering the robot's mass, this will stop your car flying around and make the robots fly away faster
Tried bumping the car's rigid body all the way up and EnemyRobot only has character controller. Still having same issue. Thanks for the response though!
character controllers don't get affected by physics, consider using a rigidbody ins$$anonymous$$d or as well as. Destroy the character controller on collision and the robot should fly away.
I'm not using physics to animate EnemyRobot tumble. I animated the moves myself. Seems the car is still reacting to the EnemyRobot Character Contoller. I want the car to pass through all the robots but trigger the correct hit animation. I appreciate the help though.
What's happening is probably the car is clipping through the model before the trigger can register because it's going too fast. What you can do is decrease the fixed time interval in preferences so that there are more physics simulations per frame. Another thing you can do which is a bit more hacky is to create a trigger on the front of your car that's proportional to speed which catches the robots before they hit the car
Your answer

Follow this Question
Related Questions
Colliding two GameObjects 1 Answer
OnCollisionEnter() not getting called between two rigid bodies 3 Answers
simple onCollision and onTrigger problem 1 Answer
OnTriggerEnter do not triggers 1 Answer
Play Audio on Collision or Trigger Enter 4 Answers