Im trying to get my character to float by counteracting gravity. My mass is 1 so this shuld work right?:
GetComponent<Rigidbody>().AddForce(new Vector3(0,9.81f,0));
This force seems way to high (even tho it seems right to me) since the caracter just takes of into the skies. At 3.5 im almost floating. I also tried this with the same results:
GetComponent<Rigidbody>().AddForce(-Physics.gravity);
So why is this not working? thanks in advance.
I think your problem is related to using these lines of code in the Update function and not Fixed Update. If you are calling the code you showed in the FixedUpdate event, and it is still not working, you can try adding the velocity change in the Y component directly:
// use this outside of FixedUpdate for better performance
Rigidbody rb = GetComponent<Rigidbody>();
// counterbalance the velocity implied by the gravity
rb.velocity -= Physics.gravity*rb.gravityScale;
You can specify a ForceMode enum in the AddForce method. In your case I think you want to use ForceMode.Acceleration, as you want to apply an acceleration that is unaffected by the mass of your rigidbody, just like gravity is.
You might also consider just using GetComponent().useGravity = false;