- Home /
Addforce and fixedUpdate()
Hi, I have two rigidbodies that collide and when this happens I want one (object A which has the code below) to exert a force on the other (object B). The collision is 'registering' and something is happening (a slight jolt in position of object B, but not what I was after). Here is the code:
void OnTriggerEnter( Collider other )
{
if ( other.gameObject.layer== INTERACTIVE_LAYER )
{
other.gameObject.rigidbody.AddForce( Vector3.forward * 900.0f, ForceMode.Acceleration );
}
}
So I guess I have two questions: 1. What am I doing wrong? 2. As all physics updates is dealt with within FixedUpdate(), should I rather be setting a flag here, then telling the FixedUpdate() function in object B to AddForce? It seems messy and I haven't seen it done elsewhere, but I thought I'd ask.
Thanks guys!
Hey, object A ( the one with the above code) is kinematic - the object I'm applying the force to, isn't.
Is the "Is Trigger" option enabled for the collider? The OnTriggerEnter function won't be called unless it is enabled (I'm not sure if that is what you mean by "registering").
Answer by Fattie · Aug 30, 2012 at 04:02 PM
I have a feeling that very simply you have the masses, sizes, or physic-materials totally wrong somewhere.
Note that in Unity3D you must use real-life meters and real-life kilograms.
So go through and check those are all absolutely correct.
Finally check the physic-materials you are using, perhaps try making them highly bouncy for a big effect. And set all friction really low.
Hope it helps.
The mass is ignored with Force$$anonymous$$ode.Acceleration or Force$$anonymous$$ode.VelocityChange.
But physic materials and/or settings such as linear drag can be a good lead.
Thanks for the assist guys. It turned out it was indeed the physics materials, as soon as I'd sorted those I received the results I was expecting. @Fattie, yeah I understand your point about combined forced (as in physx and then me applying a force on top), effectively I want one object to hit another and havea large force, which I guess I should be achieving by tweaking the material types and mass of each object?
funnily enough another rigging question that just came up. it will perhaps give you more of the flavour of how to solve these issues
http://answers.unity3d.com/questions/310986/skip-stone-in-to-water.html
remember in video games, always go for the smart-arse solution that saves you doing any actual work or math !! :)
Your answer
Follow this Question
Related Questions
OnTriggerEnter AddForce OK??? 1 Answer
Add force in the OnStateUpdate. 0 Answers
Moving an object using rigidbody.AddForce & keyboard input. 1 Answer
Mistake in Function with Collision and AddForce 0 Answers
AddForce in Update 1 Answer