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 /
  • Help Room /
avatar image
0
Question by spuller · Feb 25, 2017 at 09:33 PM · collisiongameobjectcolliderchildforce

How to get the child collider of your own player when there is a collision between two players.

Hi,

I need a little help with detecting which collider my car hits another car with. Each car has several collider, but the one I'll be focusing on is the front collider. If I hit another car with my front end, I need it to add extra force to the hit. I don't care where I hit the other car, I just want to know, if I hit the car with my front collider (my child collider) add the extra force against the other car.

I've tried this:

  private void OnCollisionEnter(Collision collision)
     {
 
         // If the object we hit is the enemy
         if (collision.gameObject.tag == "Player")
         {
             if(collision.collider.name == "FrontCollider")
             {
                
                 float theirMagnitude =      collision.gameObject.GetComponent<Rigidbody>().velocity.magnitude;
                 float yourMagnitude = thisRigidbody.velocity.magnitude;
                 
                     float difference = thisRigidbody.velocity.magnitude - collision.gameObject.GetComponent<Rigidbody>().velocity.magnitude;
                 Debug.Log("hit");
                 // Calculate Angle Between the collision point and the player
                 Vector3 dir = collision.contacts[0].point - transform.position;
                     // We then get the opposite (-Vector3) and normalize it
                     dir = dir.normalized;
                 // And finally we add force in the direction of dir and multiply it by force. 
                 // This will push back the player
                 collision.gameObject.GetComponent<Rigidbody>().AddForce(dir * extraForce * thisRigidbody.velocity.magnitude);
             }
             
         }
 
     }


The only problem is that when I collide with another car, it only works when I hit the front end of the other car. How do I ignore the other collider of the other car and only worry about my own child collider.

Thanks in advance. I appreciate it.

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

0 Replies

· Add your reply
  • Sort: 

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

139 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Remove Object from Game after Collision with Player (Unity 5.2.3f1) 1 Answer

Using Else on OnTriggerStay, do a game over if i click when i dont have a box on it the collidor/mesh. 0 Answers

How to Destroy A GameObject when it enters any Triggers 2 Answers

Getting Parent object from a child's collision. 1 Answer

How to set GameObject created by MenuItem as a child of Canvas 0 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