- Home /
Rigidbody and addforce to center of object? JS
Hi guys!
Currently I have an object that jumps up using the rigidbody.addforce function but now I realize I need the force to go to the center of the object or a pivot point (it is linked with a fixed joint to another object) and not just up. Currently it looks like this : if (Input.GetKeyDown (KeyCode.Space)){ GetComponent.<Rigidbody>().AddForce(new Vector3(0, 10, 0),ForceMode.Impulse);
but I don't know how to change the new Vector3 to the center/pivot of the object. Help would be greatly appreciated.
Answer by FunIsDangerous · Jul 04, 2017 at 03:27 PM
This should work
GetComponent.<Rigidbody>().AddForceAtPosition(new Vector3(0, 10, 0), transform.position, ForceMode.Impulse);
Also, for optimization's sake, you should have a variable Rigidbody rigidbody
, and on Start set it to GetComponent.<Rigidbody>()
instead of getting it each time.
Thank you so much but (new Vector3(0, 10, 0) still makes it just go up right? I'm missing the part where the force is actually going to a targeted object.
Right but I want it to go into the direction of the center of the object not up :P
Your answer
![](https://koobas.hobune.stream/wayback/20220612125513im_/https://answers.unity.com/themes/thub/images/avi.jpg)