3

I am creating a 2D autoscroller and when my player (with a circle physicsBody) collides with an SKAction moveTo-powered obstacle which is moving towards it, it makes small, almost unnoticable lags. I tried lowering the friction and the density of the objects, but nothing helped. Any ideas?

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
  • Could you define lag? is the entire game slowing down and FPS dropping, or is your character just getting stuck when hitting an object – Knight0fDragon Aug 29 '16 at 14:56

2 Answers2

3

You have chosen to use a circle with phycsicsBody. An SKPhysicsBody object is used to add physics simulation to a node. When a scene processes a new frame, it performs physics calculations on physics bodies attached to nodes in the scene. These calculations include gravity, friction, and collisions with other bodies. After the scene completes these calculations, it updates the positions and orientations of the node objects.

You have also chosen to use SKActions, when using the actions to move a body such changes don't go through the physics engine, indeed usually you could add unwanted actions and unexpected events as "bouncy lags".

So, if you're using physics to move a body, you shouldn't use move actions, apply an impulse or force, or set it's velocity directly

Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
0

Setting restitution to zero may help. This controls the elasticity, or bounciness of a sprite.

R.P. Carson
  • 439
  • 5
  • 20