0
\$\begingroup\$

I've spent hours trying to find the problem with this:

if (Input.GetKeyDown(KeyCode.Q))
{
    playerController.rb.AddForce(new Vector2(-forceAmount, 0), ForceMode2D.Impulse);
}
if (Input.GetKeyDown(KeyCode.E))
{
    playerController.rb.AddForce(new Vector2(0, forceAmount), ForceMode2D.Impulse);
}

When I press E force is applied upwards normally, but when I press Q nothing happens.

I checked the rigidbody and the physics material, and the issue doesn't come from those because I changed the Mass and the Gravity Scale of the player, changed the friction of the PhysicsMaterial2D to 0 and non 0, and applied force while the player is in the air, but none of them worked.

\$\endgroup\$
2
  • \$\begingroup\$ Do you have any other code manipulating this object's position or velocity? It's possible the impulse is getting applied, but is immediately overridden. There's no inherent bug in AddForce that limits the directions it acts in - that would have been discovered long ago by thousands of developers if it were the case. So it has to be something else in your project causing it. Try duplicating your project and strip away everything you can while preserving this glitch. This will help you make a Minimal Complete Verifiable Example: the smallest set of code and scene setup that contributes to it. \$\endgroup\$
    – DMGregory
    Commented Oct 6 at 11:23
  • \$\begingroup\$ I've disabled the PlayerController script and now it works properly, thank your for the suggesting of striping things from the project. \$\endgroup\$ Commented Oct 6 at 13:38

1 Answer 1

1
\$\begingroup\$

The problem was that the PlayerController was interfering with the other script.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .