0
\$\begingroup\$

I'm currently developing a simple breakout/arkanoid mobile game. Now, I noticed that my ball movement is noticably stuttering. I've read various approaches about how to make the ball move and decided to go for AddForce so I don't have to do any physics calculations myself. The only thing im currently doing is using AddForce on my ball's rigidbody2D and have it collide with the walls and blocks. There's nothing done manually in Update or FixedUpdate and there are no other scripts running while the ball is moving. The scene is pretty empty actually.

Things I have tried so far without success:

  • Disable V-Synch
  • Increase the velocity iterations (I tried values 15-500)
  • Set the RigidBody2D's interpolation mode to: Interpolate/Extrapolate
  • Using different mass values and force values in AddForce
  • Checking, whether it's just an optical illusion (it seems to run more smoothly in editor and other breakout/arkanoid games don't have that problem on my Galaxy S7)

RigidBody settings of the ball:

  • Body Type: Dynamic
  • Material: Friction: 0 | Bounciness: 1
  • Mass: 0.025
  • Linear Drag: 0
  • Angular Drag: 0
  • Gravity Scale: 0
  • Collision Detection: Continous
  • Sleeping Mode: Start Awake
  • Interpolate: Interpolate

The walls and blocks are simple BoxCollider2D components. And I'm calling AddForce(new Vector2(0f, GameConstants.DESIRED_BALL_SPEED)) on the ball's RigidBody2D.

Edit:

public void OnPointerUp(PointerEventData eventData) {
    if(!_ballStarted) {
        PaddleController.ShootStickingBalls();
        _ballStarted = true;
    }
}

public void ShootStickingBalls() {
    int stickyBallsAmount = _stickingBallsRigidBody2D.Count;
    for (int i = 0; i < stickyBallsAmount; i++) {
        _stickingBallsRigidBody2D[i].AddForce(new Vector2(0f, GameConstants.DESIRED_BALL_SPEED));
        _stickingBallsRigidBody2D[i].transform.SetParent(_nonStickyBallsTransform);
    }
    Sticky = false;
}
\$\endgroup\$
  • \$\begingroup\$ Can you show us within the context of your code where you're calling AddForce? \$\endgroup\$ – DMGregory Nov 24 at 16:56
  • \$\begingroup\$ @DMGregory I have edited my post. \$\endgroup\$ – iQew Nov 24 at 17:15
  • \$\begingroup\$ Could this be related to some quality settings of some sort? I haven't touched anything of them and am just using ultra low settings. \$\endgroup\$ – iQew Nov 24 at 17:23
0
\$\begingroup\$

My intuition on this was correct, it was indeed a general performance problem. I've deactivated all unnecessary quality settings on the camera object (HDR, MSAA, etc.) and now it's running smoothly.

\$\endgroup\$

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.