Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DigitalDogfight · May 07, 2010 at 04:19 AM · ontriggerenteroncollisionenter

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 ();    

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DigitalDogfight · May 07, 2010 at 06:59 PM 0
Share

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!

avatar image spinaljack · May 07, 2010 at 10:24 PM 0
Share

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.

avatar image DigitalDogfight · May 08, 2010 at 06:30 AM 0
Share

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.

avatar image spinaljack · May 08, 2010 at 10:51 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges