i am making a 2d rocket type game and i am trying to use rigidbody2d.AddForce with forcemode2d to propel the object
public Rigidbody2D rig;
public float jumpHeight; // set in inspector to 5f
public bool applyForce;
// Update is called once per frame
//checks for input if you are holding down on 'w'
void Update ()
{
if (Input.GetKey("w"))
{
applyForce = true;
}
else
{
applyForce = false;
}
}
private void FixedUpdate ()
{
Ignition();
}
// the function which calls on addforce
public void Ignition ()
{
if (applyForce)
rig.AddForce(new Vector2(0, jumpHeight), ForceMode2D.Force);
}
i tried by calling “Ignition()” in Update and it worked fine, and i tried it in fixed Update and nothing happens, no errors or movement. i tried to run ForceMode2D.Impulse instead of ForceMode2D.Force in fixed update and that worked but i need to use it as a force not impulse anyone know how?
unrelated to the question but if you also know how to change a rigidbodies mass in the script that would help me. also if you know how to change gravities value in physics that would help. Thanks in advance!