Physics Possibilities?: Angles, Penetration, Exceptions

I’m definitely a newbie to physics, so I’m curious about a few things.

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 hits the other tank. Can Unity calculate if the shell should bounce off the tank based on the angle and thickness of the armor. Is there a way to detect how “thick” the shell’s flight path would be through the armor at its current angle? That is, if it hits at 90 degrees, the thickness of the armor between entry point and exit point would not be as thick as if it hit 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 this knight, there is a trigger collider that extends about 10 feet in every direction. Is there a way for this 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 think about things. 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 achieved 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.

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 something to pierce, you do not assign a rigidbody to that item.

The Collider and Collision classes, PhysicsMaterials and Joints describe just about everything the Physics system can do. I think 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 anything that you listed above. I don’t think 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 things are possible using Unity.

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

Example 1: A tank fires its cannon at
another tank. The shell hits the other
tank. Can Unity calculate if the shell
should bounce off the tank based on
the angle and thickness of the armor.
Is there a way to detect how “thick”
the shell’s flight path would be
through the armor at its current
angle? That is, if it hits at 90
degrees, the thickness of the armor
between entry point and exit point
would not be as thick as if it hit 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 thickness 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 something 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 this knight, there is a
trigger collider that extends about 10
feet in every direction. Is there a
way for this 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 things 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 things 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 something to stick… parent it, and stop simulating it.

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 thin 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.