Measuring the pressure on a rigidbody / Squashing

Hello everybody,

i’m just curious if there is a way to measure the pressure that is applied to a single rigid body.
I’m now trying a jump’n’run based side scroller,
and it will be possible for the character to be crushed between two moving walls, or between one of these walls and the ground, and so on…
but he should not simply die by touching on or even more moving walls, it should only die if it is actually crushed.

Is there an easy way of measuring that using physics ?

One way would be to create triggers up and down of the character, and check if both are touched by moving objects, same for left and right, but then, the characters should not die by the touch itself bu only if the sides are pushed strongly enough … if did that way, even light crates could smash it…

to put it short: i’m just searching a simple&elegant way of doing that.

You could link the triggers to a spring joint and calculate the distance between them; taking into account the “Spring” parameter of the joint would enable you to determine the pressure applied.

If you want to push for “realism”, I’d suggest using the Min Distance as a conditional check to see when your character is automatically killed by the pressure (a.k.a. mortally squished between objects).

hi,

thanks for your quick reply,
thats an interesting idea.

I’ll try that out as soon as i have my obstacles up and running :slight_smile:

(actually, i ask for some problems sooner than i encounter them, because i’m not always so lucky that my answers are arriving that soon)

Hi,

i’m sorry to tell that it didn’t worked at all …
The spring joints jumps around like crazy … if i parent it, it moves not only to the other side,
but somewehere else … seems, that the joints are caching there positional values somewhere inside their code …
aditionally, it has a sucking effect on the position of the player, if it moves too far.
Next thing i tried was using a configurable joint … which i used at first to make this game 2D (locking an axis).
I added a break force to it … but, i couldn’t say what forces there are at work … i could sometimes drop a very massive object
from a high distance at the head , and nothing happened … then, when the hero jumped on a platform,
with very small velocity, it suddenly broke
(the hero, as well as this platform, were very light).

So i guess i’ve to figure out something else.
Next thing that i’ll try will be permanent raycasts through the bounding box of the character… or using the bounding box itself to
check if there are touches at (left&right) || (up&down) … yes … that’s, what i’ll try out next!

i wonder…

you might be able to write a few scripts so that while one object is in contact with another, if it’s over top of the other one, it sends a message to that object telling it about it’s mass, and the accumulated masses of any objects that have been on top of it.

yeah, it looks like you could use:

OnCollisionStay

OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.