0
\$\begingroup\$

I'm having trouble making a character move faster than a certain limit using RigidBody2D.AddForce(). My game is a top-down 2D game (constrained to the x/y plane).

I'm using a float 'MovementSpeed' to scale a normalized vector passed to RigidBody2D.AddForce(), however, when I increase MovementSpeed past 1000, there's almost no noticeable difference in the object's "speed"; going from 100 to 1000 is a drastic difference, but there's almost no noticeable difference going from 1000 to 1000000. Here's my WASDMovement() function (called during FixedUpdate() ):

private void WASDMovement() {
    Vector3 translationVector = Vector3.zero;

    if (Input.GetKey(KeyCode.W)) {
        translationVector += new Vector3(0.0f, 1.0f, 0.0f);
    }
    if (Input.GetKey(KeyCode.A)) {
        translationVector += new Vector3(-1.0f, 0.0f, 0.0f);
    }
    if (Input.GetKey(KeyCode.S)) {
        translationVector += new Vector3(0.0f, -1.0f, 0.0f);
    }
    if (Input.GetKey(KeyCode.D)) {
        translationVector += new Vector3(1.0f, 0.0f, 0.0f);
    }

    translationVector.Normalize();
    rigidbody2D.AddForce(translationVector * MovementSpeed);
}

Here's a video demonstrating my problem to make it easier to see what I'm doing wrong: http://youtu.be/9kwKvfDOYoo

\$\endgroup\$
  • \$\begingroup\$ Please accept the answer so the site won't keep bringing your question up to the front page, thank you \$\endgroup\$ – Daniel Carlsson Feb 16 '15 at 9:47
1
\$\begingroup\$

A friend found a potential solution by increasing the Physics2D.velocityThreshold constant, I'm not able to test it currently since it's a 4.5 feature and I currently use 4.3 (downloading/installing 4.5 right now).

\$\endgroup\$
  • \$\begingroup\$ This was confirmed to be the issue. Upgrading to 4.5 allowed me to control Physics2D.velocityThreshold so that I could use AddForce() with higher magnitudes. \$\endgroup\$ – James Linden Sep 18 '14 at 23:21

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.