- Home /
One way physical forces during collision?
I have a situation where a boulder is rolling down and pushing away rigidbodies as it roles. The rigidbodies are kinematic until 'oncollision' is called afterwhich the kinematic value is set to false so they get pushed by the boulder.
When a boulder hits these rigidbodies it often slows down for a bit before continuing on again.
What I would like is the boulders forces to apply to the rigidbodies but for any stopping power the rigidbodies have to be nullified.
Any ideas how I can do that? Currently I just add extra force to the boulder but that makes it look very unrealistic at times.
The answer could not be easier.
$$anonymous$$ake the big boulder really heavy.
Another incredibly simple solution:
Add a script to the small rocks that says: "Have I just been hit? Then add a large force to myself (in that same impact direction)".
Easy!
I'm glad you didn't make this an actual answer, because I'd have had to downvote it. There are physics glitches in Unity that prevent this approach from working properly- my method bypasses all of these.
Sorry, ever since it started using 'real names' as the labels on posts, it's been a little confusing! I'm $$anonymous$$ieren.
$$anonymous$$ainly, I object to the 'booster rocket' idea. That kind of behaviour is basically not consistent with physics, and while it can be a nice looking effect in places (with bits flying everywhere), it doesn't really make sense. I find that friction can play an unexpected part in this kind of interaction, as well- incorrect forces will be calculated if you leave it up to the physics engine, so it's best to provide a simplified model, and fake the rest.
Gotchya ... hmm, I absolutely admire your method and sometimes add a "virtual" collider for one reason or another - awesome. But I'm not sure which glitches you're referring to (if you simply add a let's call it "booster rocket!") - if you get a chance tell me. I don't want to glicthes ;-) cheers mate
Answer by syclamoth · Jun 10, 2012 at 01:27 PM
So far, I know of no way to do this that doesn't involve faking the large boulder's physics in some way.
So, try something like this: Make a kinematic rigidbody (with a collider), that is a child of the boulder. It should have the same shape, so that it will collide with objects in the same way.
Then, put all your 'detritus' objects on their own collision layer- they should collide only with the floor, and each other (not the big boulder!).
Having done that, make the second collider on the boulder (the fake one) collide with the detritus- so that you have the main boulder actually acting with physics, and the fake boulder pushing all the little things away before it!
Basically, the answer is clever manipulation of collision layers.
Answer by muffinhat · Jun 10, 2012 at 07:15 PM
are you using C#? Add this:
rigidbody.Addforce(Vector3.down * 500);
I am fairly new to rigidbody scripts, but I beleive you add an 'if' statement testing a collision, leading to a rigidbody force. I'm sorry if this isn't specific enough, but I hope it helps! :)
Answer by Sapidus3 · Jun 10, 2012 at 03:54 PM
Well what you are wanting to do doesn't happen in real life, so the physics engine probably wouldn't like that. You could try tricking it like Kieren said, however I would imagine you could also increase the boulders mass. Changing the mass won't change the rate at which it "falls".
If the boulder is massive compared to the things it is hitting will have the collisions have a smaller impact on the boulder. The documentation suggests that you don't make anything more than 100 times more massive than something else. So if you have not changed the default mass of your your other objects, go ahead and try setting the boulders mass to 100 (you may need to change the force you are pressing the boulder with).