• 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
Question by DCTShinobi · Jan 26, 2015 at 02:18 PM · physicsrigidbodycollidertriggerpenetration

Physics Possibilities?: Angles, Penetration, Exceptions

I'm definitely a newbie to physics, so I'm curious about a few t$$anonymous$$ngs.

Does the Unity physics engine support collision detection and calculations in a following example?

Example 1: A tank fires its cannon at another tank. The shell $$anonymous$$ts the other tank. Can Unity calculate if the shell should bounce off the tank based on the angle and t$$anonymous$$ckness of the armor. Is there a way to detect how "t$$anonymous$$ck" the shell's flight path would be through the armor at its current angle? That is, if it $$anonymous$$ts at 90 degrees, the t$$anonymous$$ckness of the armor between entry point and exit point would not be as t$$anonymous$$ck as if it $$anonymous$$t at 45 degrees.

Example 2: An arrow is shot at a bale of hay. Can Unity determine if the arrow has enough power to penetrate partially or completely through the bale of hay? And can the bale of hay slow the arrow down along its path until it either stops or completely exits the target?

Example 3: Like in example 2, if a plate of metal armor were placed in front of the hay, does Unity support instant calculations whether an object should penetrate a collider or bounce off depending on the force?

Example 4: There is a knight in armor. The armor has a physics collider. Surrounding t$$anonymous$$s knight, there is a trigger collider that extends about 10 feet in every direction. Is there a way for t$$anonymous$$s trigger collider to detect any arrow or weapon that enters it, compare values assigned to it (penetration power, velocity, etc.) to values assigned to the armor (penetration resistance, etc.), then, if applicable, to tell the armor collider to ignore that specific object?

Question: Is it possible for a rigidbody to partially penetrate another rigidbody on purpose? Or even get one stuck into another deliberately without relying on bugs and glitches?

Yes, many questions. I'm just trying to find the best way to t$$anonymous$$nk about t$$anonymous$$ngs. If there are such possibilities, any explanation or examples how to accomplish them would be greatly appreciated.

Thank you very much!!!

Ps. For Example 2, I ac$$anonymous$$eved the slowing of the arrow by using a trigger as the target and a rigidbody on the arrow.

For Example 4, I know how to create exceptions for collisions ahead of time by writing them in scripts. But I do not know how to script for any given exception on the fly.

Comment
Kerfuffle37

People who like this

1 Show 0
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

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by DanSuperGP · Jan 27, 2015 at 01:25 AM

Example 1: A tank fires its cannon at another tank. The shell $$anonymous$$ts the other tank. Can Unity calculate if the shell should bounce off the tank based on the angle and t$$anonymous$$ckness of the armor. Is there a way to detect how "t$$anonymous$$ck" the shell's flight path would be through the armor at its current angle? That is, if it $$anonymous$$ts at 90 degrees, the t$$anonymous$$ckness of the armor between entry point and exit point would not be as t$$anonymous$$ck as if it $$anonymous$$t at 45 degrees.

In OnCollisionEnter you could get the normal of contact point, and then take the dot product of that and the projectile's velocity to determine the angle of collision. Then you could determine the t$$anonymous$$ckness yourself.

Example 2: An arrow is shot at a bale of hay. Can Unity determine if the arrow has enough power to penetrate partially or completely through the bale of hay? And can the bale of hay slow the arrow down along its path until it either stops or completely exits the target?

In OnCollisionEnter you could get the relative velocity from the collision point yourself... and then decide yourself if that's enough power to penetrate the hay bale then you can add force in the opposite direction of it's velocity to slow it down or stop it completely.

Example 3: Like in example 2, if a plate of metal armor were placed in front of the hay, does Unity support instant calculations whether an object should penetrate a collider or bounce off depending on the force?

OnCollisionEnter happens before the physical results of bouncing off a collider happen... so you can decide to change collision layers or somet$$anonymous$$ng so that it will penetrate along with applying force to slow it down.

Example 4: There is a knight in armor. The armor has a physics collider. Surrounding t$$anonymous$$s knight, there is a trigger collider that extends about 10 feet in every direction. Is there a way for t$$anonymous$$s trigger collider to detect any arrow or weapon that enters it, compare values assigned to it (penetration power, velocity, etc.) to values assigned to the armor (penetration resistance, etc.), then, if applicable, to tell the armor collider to ignore that specific object?

Yes, you put a capsule collider around the armor, set to trigger... and then do your calculations in OnTriggerEnter... then you put the arrow into a layer that doesn't collide with the armor or not... depending on your calculations.

Question: Is it possible for a rigidbody to partially penetrate another rigidbody on purpose? Or even get one stuck into another deliberately without relying on bugs and glitches?

Sure... You make them not collide by putting them on separate layers... and then reduce the velocity or stop the projectile... Then if you want one of them to get stuck... you parent the one you want to get stuck to the one you want it to stick in. (usually it's a good idea to set it to kinematic or deactivate the rigid body at that point)

The long and short of it...

Unity isn't going to DO any of the stuff you want for you. But it does give you tools to do all of it yourself if you know what you want and how to do the relevant math.

Some t$$anonymous$$ngs to keep in mind...

If you're doing physics... you need to know linear algebra. Math is an important part of game development... like how to use the dot product to find the angle for example one.

When you want t$$anonymous$$ngs to collide or not collide, the best way to do it is to use collision layers. You can change layers on the fly at any time, obviously in OnCollisionEnter is a good time.

If you want somet$$anonymous$$ng to stick... parent it, and stop simulating it.

Comment
DCTShinobi
Occuros
Kerfuffle37

People who like this

3 Show 1 · 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 DCTShinobi · Feb 05, 2015 at 07:29 AM 0
Share

Ah, quite the explanations. Thank you.

Yes, I ended up using the concept of Example 4. I used a large trigger collider to determine if any entering objects should get past the armor (non-trigger collider). If so, instead of using different physics layers, I simply used "Physics.IgnoreCollision" and applied the armor's and arrow's colliders. That way, if there was another knight with stronger armor in the same area, his armor would not be effected.

I have a trigger collider of the same shape and position is the armor's collider (on a different layer) which is what the arrow would penetrate into and through if the arrow is strong enough, but it could get stuck and parented if it is slowed down enough.

However, if the arrow entering the first trigger is found to be too weak, then nothing happens to it in the script, so it bounces off the armor like it should.

I did try to use OnCollisionEnter on the actual armor to determine if it should ignore the collision, however, the arrow still seemed to glance off slightly, so I like the method I went with.

avatar image

Answer by sniper43 · Jan 26, 2015 at 03:33 PM

As rigibody currently works (as far as I've gathered) it cannot seperate a single object. It cannot turn a sphere into 2 half spheres. It works simply by checking wheter or not 2 objects collide (triggers the OnCollide event) and calculates a new velocity based on both object's rigibody mass and current velocity according to the location of impact.

Turning one object into 2 objectsis very hard.

Making a hay bale, as described in your example, is also very hard. You have to basically set it up as a static collider that greatly increases the drag of whatever object enters it, and resets drag as it leaves.

Rigidbodies don't really have a "penetration" function. They serve as collision detectors that handle collisions accordingly, and you can look through

http://unity3d.com/learn/tutorials/modules/beginner/physics

for more info.

If you really want somet$$anonymous$$ng to pierce, you do not assign a rigidbody to that item.

Comment
DCTShinobi

People who like this

1 Show 3 · 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 DCTShinobi · Jan 27, 2015 at 12:42 AM 0
Share

Thank you.

Yes, as for the hay bale example, I managed to simulate that with a trigger collider (please forgive my terminology, I'm still trying to grasp the different types of colliders). The arrow has a non-kinematic rigidbody. As the arrow enters the trigger, drag is applied to the arrow, and drag is continually applied until the arrow exits the trigger (if it does). Once the arrow exits, the original drag is reset.

Let me ask this. Is there a simple way to get the arrow's velocity? I want to be able to stop applying drag and set the hay bale to be the arrow's parent once the arrow's velocity is 0. I know how to do everything except to get the current velocity.

I didn't know if Unity has a velocity variable somewhere, or if I'll just have to compare positions over frames.

Thanks again!

avatar image sniper43 · Jan 27, 2015 at 12:32 PM 1
Share

Rigidbody.velocity getrs you the direction of the item as well as the force apllied. Getting the magnitude of the Vector3 velocity gets you a force.

So getting Rigidbody.velocity.magnitude SHOULD get you the amount of force. You can simply check for

 if(Rigidbody.velocity == Vector3.zero)
avatar image DCTShinobi · Feb 05, 2015 at 07:11 AM 0
Share

Thank you. Yes, after finally being able to work on it it again, I was able to test if the "arrow's" velocity was at 0. If so, I deleted its rigidbody and collider, then set the target object as the parent. The arrow even stay in place, and would then move with the target. So everything seems to work just fine.

avatar image

Answer by Owen-Reynolds · Jan 26, 2015 at 04:51 PM

The Collider and Collision classes, PhysicsMaterials and Joints describe just about everyt$$anonymous$$ng the Physics system can do. I t$$anonymous$$nk it's all pretty standard rigidbody stuff (it's 3rd party PhysX, I believe, so can read about that; or really, any game physics engine.) It's good at making solid objects bounce off of each other and roll realistically.

It can't do be auto-configured to do anyt$$anonymous$$ng that you listed above. I don't t$$anonymous$$nk anyone would want it to, since it would run too slow for its usual purposes. But Unity is very programmable, and you have access to any of the angles, etc... that you need to do the math yourself. Any of those t$$anonymous$$ngs are possible using Unity.

But, each would be a specific question with a specific set-up and multiple answers depending.

Comment
DCTShinobi

People who like this

1 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 DCTShinobi · Feb 05, 2015 at 07:37 AM 0
Share

Very true, thank you. I guess I just like to search for "shortcuts" that Unity may hold that I am not aware of. For example, using "transform.forward" instead of having to find and enter the specific numbers myself.

In fact, I just found out the new UI system has something called "Grid Layout Group" hidden away.... after I spent days writing my own code to do the same thing, haha! Well, at least I know how to create such a thing now :-)

avatar image Owen-Reynolds · Feb 05, 2015 at 07:03 PM 1
Share

A lot of it is just familiarity. For example, people who use 3D programs know about the little local/world arrows, and they assume there's probably a way to get the local forward arrow in a script. So much in Unity is just general game engine knowledge.

Put another way, learning Unity as a first game engine is really learning game engines, and learning Unity.

avatar image

Answer by stuartiannaylor · Nov 01, 2019 at 07:00 PM

Isn't the main problem that only convex mesh colliders can be used? A convex mesh collider only has a max of 255 triangles and it will approximate a best fit of your tank model. Its very likely the result is like your model being wrapped in t$$anonymous$$n card around the most external vertices. Depends on your model but likely absolutely useless for any form of accurate armour profile.

I am beginning to wonder if its better to add extra slightly oversized box trigger colliders for the turret and hull (Oversized as getting the target object in a box space). I am hoping you can get a mesh triangle from a coordinate but haven't googled that so far.

Comment

People who like this

0 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to combine child trigger of a object to only trigger OnTriggerEnter once? 1 Answer

How do i get OnTriggerStay2D to work? 1 Answer

Rigidbody.SweepTest Hit Trigger Colliders 0 Answers

Gravity is preventing object from moving straight toward its direction when calling rigidbody.AddForce... 1 Answer

Collider IsTrigger won't work correctly with close second Collider 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