2
\$\begingroup\$

In unity I have a rigid body object and would like to apply force to a specific point. For example say I had a cube, I want to hit just the top right corner so it spins as a result. One idea I had considered is spawn a small sphere and fire it at it, then destroy the sphere. But is there a way to just apply the force?

\$\endgroup\$
3
  • \$\begingroup\$ It's easier for us if you specify the engine in more than just the tag. And what have you tried? \$\endgroup\$ – Almo Dec 19 '12 at 21:57
  • 2
    \$\begingroup\$ The first words are the engine I'm using, and the ball thing was all I had tried, and for the record throwing a ball of considerable mass (like a cannon ball) at a ragdoll is incridbly fun \$\endgroup\$ – ProtoJazz Dec 20 '12 at 2:40
  • \$\begingroup\$ Woops! Somehow I missed the "in unity" part. I just started at "I have a rigid body" for some reason! :) \$\endgroup\$ – Almo Dec 20 '12 at 13:20
3
\$\begingroup\$

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html

void ApplyForce(Rigidbody body) {
    Vector3 direction = body.transform.position - transform.position;
    body.AddForceAtPosition(direction.normalized, transform.position);
}
\$\endgroup\$
1
  • \$\begingroup\$ I suppose that does answer it. I hadn't found that function. Now I just have to figure out how to get the vector 3 of the point I want to apply force to. I'm guessing the fps tutorial is my next step then \$\endgroup\$ – ProtoJazz Dec 20 '12 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.