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;
}