- Home /
"Padded objects" type collision .. any ideas?
You wake up in a room with padded walls ..
Imagine a 1 meter block colliding with a large wall in Unity. They both have typical say metal-like PhysicMaterials.
In this example, picture SLOW movement and collisions. (Like the spacecraft floating around in 2001...)
Obviously, nothing happens until the moment something touches, and then PhysX correctly provides I suppose
That's all great ... Now imagine if both objects were covered in padding, say about 5 cm or 10 cm thick.
The collision would be quite different (I think??!) - sort of squidgy, slowing down after the padding started to interact.
Has anyone done this. or can think of a good approach, or does it exist already?
My only idea was to: add a manually force field that extends 5+5 = 10 cm from the wall in the example, and ends abruptly. (I guess, implement this simply with yet another collider, as a trigger). Inside that "quantum of rubber padding" I guess you would just simply add a fixed force pushing the cube away {questions arising, would it vary with distance, or not even - how do padded walls behave?}. I suppose, it would slow it down more on the way in and speed it up more on the way out.
An extreme example - imagine throwing a ball towards a very powerful fan blowing air. That would eventually stop the ball and push it away - a kind of a bounce. I suppose, that's sort of like the solution I describe.
Or, would it be best to use the mechanism I describe, just alone without a normal collision?
Or .???
I was also thinking, is it essentially a matter of "delaying" collision. The object comes in, PhysX does everything normally, but it "hangs in space" for a few beats before firing off in the other direction. In fact, does that achieve the right feel?
Furthermore -- in fact, DOES PhysX currently do what I describe? Q, does PX wait until the moment of contact (allowing for the penetration values etc) to apply forces, or, does it start doing them when they cross some threshold and apply them over a small distance? I guess this knowledge would be critical to the issue I am asking about. (if you simply tuned that range to be bigger, that would presumably exactly achieve what I am describing.)
I also thought about arranging it so that the wall is actually a big thing which is spring'd to a real wall behind! Will springs work like that in PhysX, ie, something hitting or perhaps sitting on a object, which has a spring connection, will in fact "work" that spring? forces and events carry through to springs?
thanks for any ideas !
Answer by Muuskii · Jul 14, 2012 at 06:38 PM
Hi, I was going to work on something similar to this in my project, I just didn't get to the part where it's appropriate to add it in yet. Maybe we could work together on it. I was thinking about using the trigger method with Rigidbody.AddForceAtPosition but then we would have to find the correct position to add the force at. Unfortunately OnTrigger events don't pass contact information like a normal collision event, and we can't use a "turned off normal collision" afaik because it won't throw events.
As far as I heard from someone else on here you could use Collider.bounds Intersects to help get an idea of where you should apply the force. To answer your other sub questions; yes I think the force magnitude should be based on penetration distance that seems accurate for padded walls, just be careful that the triggers don't overlap!
If you get some code working on this I would be glad to swap pms with you on the subject.
You know, I didn't even think about the issue of "where" to add the force -- actually, I'm not sure if it matters at all ?! (Just add it centrally to the whole object.)
I guess i was thinking more of a padded ball hitting a padded wall -- but you make a superb point, I better start thinking about that :)
regarding solely what you say about finding "where" it hits. depending on the geometry involved, perhaps just stick four small triggers, for example on the corners of a cube (err, 8 on a 3d cube) in that example of a cube, it has to after all hit a corner (if it's a flat wall) so you have the answer from one of those triggers. perhaps that's a way forward regarding that issue solely.
i'll just post the full rig of anything i figure out, no worries
You'd think there'd be a latex engineer on here that can tell us the curve for rubber, what sort of lousy game programmer list is this ?! what else do you do when your job as a latex engineer gets GFC'd other than retrain as a game programmer???
Since sadly nobody else has any interest at all in this question, I have with thanks ticked your answer $$anonymous$$uuskii ! thanks for the thoughts!
Thank you. I was looking at the intersects function more closely and it seems it doesn't return contact points like I figured it would but I think you're saying that doesn't matter to you. I might have to make a custom script that does it given two colliders . . .
Right - among other things, I definitely want that contact points info you mention. (Don't forget in some situations you could possibly solve that problem just by using my trick of little colliders in the corner).
I am quite interested in the idea of making: WALLS THAT ARE ACTUALLY SPRUNG! $$anonymous$$y early tests are working great !
one thought: say you're a cube at 20 degrees off and you hit a hard wall. of course, one point hits first and that torques the cube vigorously, of course right. IF YOU HIT a "padded wall" there is LESS of that affect, it is much less vigirous. the cube can $$anonymous$$EEP it's 20 degree off, as it moves in to the padding, you know what i mean? that's worth thinking about in terms of "how padding works!
a hard wall - as well as providing instant return - instntly and fully torques objects that are off face line. BUT padded walls do that less.
BTW again it's surprising to me there are not 100 Unity programmers desperate to give an opinion on this! - heh !! thanks again for the brainstorm
Answer by Muuskii · Jul 16, 2012 at 12:57 AM
I can't believe I didn't think of this before. I'm attaching a project file so you can test out what I've been working on here. Basically what we do is make a Kinematic Rigidbody parented to a non-kinematic one separated out into collision layers so that only the first can collide with the "pad layer" we then use the contact points when the kinematic version collides with the pad to apply forces to the non-kinematic rigid body, thus the object drags through the pad slowly and can sometimes even bounce off it.
I'll need to work on calculating the force to get results more in line with a padded floor, but it certainly illustrates how this is VERY possible to do.
Hope that this has helped you out! :P
P.S. I wonder how you'd do this with a compound collider?
Spectacular, gimme a $$anonymous$$ute to look at this !!!!!!!!
TBC, you mean "only the first can " ... you mean the kinematic one collides, gives you the points, and does not actually bounce?
Yes, because kinematic objects don't get effected by collisions it stays stuck to the non-kinematic one, but! It turns out that it still calls the collision functions when it touches a rigid body collider, giving us the contact points.
It's almost TOO simple and maintainable. :P