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 Trickman · Sep 06, 2016 at 09:41 AM · collisionphysicscolliderexplosion

Enemies fly everywhere when they collide with each other

I'm making a game where several enemies are chasing you down and you can defend yourself with bombs. When these bombs hit something, they explode. When colliding with an explosion, the enemies fly away with a proportionate "explosion push force":

     // Push me back from the center of the explosion
     Vector3 fromExplosionToMe = gameObject.transform.position - objHit.transform.position;
 
 gameObject.GetComponent<Rigidbody> ().AddForce (
     fromExplosionToMe * Bomb.ExplosionPushForce * Time.deltaTime,
     ForceMode.Impulse);


The trouble is that, sometimes, when that enemy hits ANOTHER enemy while he flies away from the explosion, that other enemy flies away at massive speeds and away from the screen:

alt text

I first thought that the problem could be that I was moving the enemies towards the player with translations instead of with forces, so when a force-powered enemy collided with a translation-powered enemy it would result in awkward physics. However, after converting all the translation movements to physics, I'm still having the problem:

     // Non-physics-based movement (OLD)
     //gameObject.transform.position = 
     //      Vector3.MoveTowards(gameObject.transform.position, 
     //      player.transform.position, 
     //      MOVE_SPEED * Time.deltaTime);

     // Physics-based movement (NEW)
     gameObject.GetComponent<Rigidbody> ().MovePosition (
         Vector3.MoveTowards(gameObject.transform.position, 
         player.transform.position, 
         MOVE_SPEED * Time.deltaTime));

Has anyone had a similar experience with collisions that result from other collisons?

Thanks in advance!

collision-problem.png (27.2 kB)
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 dynamoo21 · Sep 06, 2016 at 11:48 AM

One Way to prevent is using by isKinematic Property of Rigidbody Component. When isKinematic is true the objects will not be affected by physics forces. In actual physics when an object in motion in hits another object in motion/rest, it results in force on participating bodies to the acceleration of bodies which depends on the net force and direction of the acceleration depends on the mass of participating objects. This is Newton's second law of motion. Unity physics behaves the same way.

Other Options: Layer Based Collision Detection:-

  1. Create a Layer : Edit -> Project Setting -> Tags and Layer

  2. Put the Fly GameObject/Prefab in the layer you made via Inspector

  3. Goto: Edit-> Project Setting-> Physics/Physics2D(depending upon game you are making)

  4. Look for Layer Collision Matrix.

  5. Uncheck The Collision for your Layer.

alt text


layerbasedcollision.png (65.4 kB)
Comment
Add comment · Show 2 · 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 Trickman · Sep 06, 2016 at 02:49 PM 0
Share

Thank you for your answer, but there are a few problems with it for me:

  1. I need the enemies to be affected by physics, I don't want them to be kinematic. I want them to get thrown way by the explosions and other factors, and fly away with a given force, and I want them to collide with each other in the X-Z plane and not be able to "pile up" together. I want the player to be overwhelmed by 20 enemies running towards him, but I don't want them to get "stacked" together. Everyone should occupy a space and the player should be able to use chokepoints where only a few of them may fit at a time. Think of the comic/movie 300 and how the Spartans forced the Persians to attack them in a small area where their numbers were useless :)

  2. I'm already using physics layers (I discovered them just a week ago or so, they're extremely powerful tools), but I want the "Enemies" layer to collide with itself for the reasons I just stated.

$$anonymous$$y main problem here is that Newton's second law of motion does not apply. If an enemy "A" travelling at 20 $$anonymous$$m/h hits an enemy "B" who is static, "B" may be sent flying away as well with a "Do$$anonymous$$o effect", but at 20$$anonymous$$m/h or less. He shouldn't be sent away flying at 300 $$anonymous$$m/h or something, as it is now.

In any case, thanks for your reply!

avatar image dynamoo21 Trickman · Sep 07, 2016 at 09:17 AM 1
Share

In that case what you can do is to, in the script attached to "enemy" game object either Check for the velcoity.magnitude of the object and it is exceeding your desired limit then give a proportional force to in opposite direction else you can limit the velocity using function like $$anonymous$$athf.Clamp()

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

102 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

Related Questions

Recreating 'skin width' functionality on a rigidbody? 0 Answers

Rigidbody randomly going through collider 1 Answer

How to Ignore Collisions Between a Layer and a LayerMask? 1 Answer

Why is my trigger collider acting like a normal collider? 1 Answer

Physics.OverlapSphere not detecting collision! Collision help. 1 Answer


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