0
\$\begingroup\$

I'm working on this game in Unity 2D where the user swipes to make a game object move in the direction that the user swiped in. Currently, when the user swipes it takes about a quarter of a second for the game object to respond and move in the new direction. What should I do to make the controls respond quicker? I know that with Input.GetAxis, I could make it Input.GetAxisRaw to make it more responsive. Right now it's like Input.GetAxis but I'm trying make it like Input.GetAxisRaw. (I can't use Input.GetAxisRaw because this is for a mobile game). Thanks.

private Rigidbody2D rb;
private Vector2 moveVelocity;

in void Update():

if (Mathf.Abs(lp.x - fp.x) > Mathf.Abs(lp.y - fp.y)) {   //If the horizontal movement is greater than the vertical movement...
                    if ((lp.x > fp.x)) {   //Right swipe
                        if(moveVelocity != Vector2.left) {
                            moveVelocity = Vector2.right;
                        }
                    }
                    else {   //Left swipe
                        if(moveVelocity != Vector2.right) {
                            moveVelocity = Vector2.left;
                        }
                    }
                }
                else {   //the vertical movement is greater than the horizontal movement
                    if (lp.y > fp.y) {   //Up swipe
                        if(moveVelocity != Vector2.down) {
                            moveVelocity = Vector2.up;
                        }
                    }
                    else {   //Down swipe
                        if(moveVelocity != Vector2.up) {
                            moveVelocity = Vector2.down;
                        }
                    }
                }

And void FixedUpdate():

void FixedUpdate() {
    rb.MovePosition(rb.position + moveVelocity * speed * Time.deltaTime);
}
\$\endgroup\$
1
  • \$\begingroup\$ Please show us your code in context. Chopping out small bits of it like this makes it harder for us to understand what you're doing, since we've never seen the rest of your code before. For instance, we can't see how lp and fp are defined/updated in this code. \$\endgroup\$ – DMGregory Mar 22 '20 at 3:13
-1
\$\begingroup\$

try reducing the linear drag of the player, it sometimes work

\$\endgroup\$
1
  • 2
    \$\begingroup\$ How do we know the linear drag isn't already set to zero? OP hasn't shown us their Rigidbody configuration. Also, note that they're moving the character with MovePosition, so drag shouldn't factor into the equation. \$\endgroup\$ – DMGregory Mar 22 '20 at 10:52
-2
\$\begingroup\$

Also perhaps you should increase the reaction time of the input.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Can you please explain how exactly the author of the question would do that? \$\endgroup\$ – Philipp Mar 23 '20 at 15:33
  • \$\begingroup\$ Yes. Please explain. \$\endgroup\$ – Taylor Reich Mar 23 '20 at 23:06
  • \$\begingroup\$ Sorry for the delay. Go to Edit -> Project Settings -> Input and select the corresponding input. The Sensitivity field is the speed (in units per second). The higher the value, the faster the input will change towards 1 / -1. \$\endgroup\$ – NaBUru38 May 18 '20 at 19:07

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.