0

I'm creating a game where a player navigates their vessel (SKSpriteNode A) and tries to make contact with a stationary rectangular sprite that is slowly rotating (SKSpriteNode B). They can navigate their vessel via impulses to speed up, slow down, change directions, etc. When contact is made, I use the SKPhysicsContact object's "CollisionImpulse" property to judge whether or not the collision was too harsh. Both objects have the same mass. The problem is that I'm getting inconsistent results while testing. I will collide with the object at seemingly the same speed every time and get very different CollisionImpulse values (sometimes around 10, other times around 30).

Since object A is stationary (albeit rotating) and only object B is moving, my assumption is that the CollisionImpulse value will be solely based on the speed of object B at the time of impact, but that does not seem to be the case.

Does object A's rotation affect the CollisionImpulse? Is there something else that can impact the CollisionImpulse value that I'm missing?

  • 1
    you can verify this by creating a new project, and instead of impulse, just set the velocity directly of the body, and see if the results are consistent. Their are a lot of factors at play here to when it comes to physics, remember this library is designed to be fast, not accurate, so liberties will be taken to accomplish speed over accuracy – Knight0fDragon Aug 25 '16 at 13:42
  • Good idea, and strangely enough the results are fairly consistent when I programmatically set the velocity. It's concerning that in "interaction mode", I can't seem to get consistent results. As far as you know, do other sprite-based commercial games tend to use their own logic to determine the intensity of collisions? Or do they use the built-in CollisionImpulse? –  Aug 25 '16 at 14:17
  • couldn't tell you, a lot of devs use alternatives like Box2D, which is what SKPhysics is based off of, I would think Unity and Unreal have their own physics libraries, but that is only a guess, and a lot of games are made on those engines as well/ – Knight0fDragon Aug 25 '16 at 14:19
  • Now I'm seeing the inconsistent results even when I set the velocity programmatically. I guess I wasn't letting it run long enough previously. Sprite A is stationary, Sprite B gets an impulse of -1, 0 every time. At the time of collision, Sprite B's velocity is -100,0. The CollisionImpulse is usually around 7.89, but sometimes it's over 15 and other times over 23. Very bizarre. –  Aug 25 '16 at 14:49
  • make sure you print the update times while doing these test, you may find that you hit a lag spike, and all that extra time had to get compensated in the next frame – Knight0fDragon Aug 25 '16 at 15:08
  • As a followup, I suspect there is a bug in the Xamarin SpriteKit port. I tried a few scenarios: 1) Velocity=100,0 CollisionImpulse=7.93 2) Velocity=3,96 CollisionImpulse=22.92 3) Velocity=85,60 CollisionImpulse=7.69 Scenarios 1 and 2 should have similar CollisionImpulse values. I verified that the update times are as expected. I also verified that it’s not just happening in the iOS Simulator — it’s happening on an actual device as well. –  Aug 25 '16 at 15:15
  • 1
    I believe xamarin uses the sprite kit library from apple, it is not a port. I do not use xamarin though so I cant be positive – Knight0fDragon Aug 25 '16 at 15:17
  • Appreciate the feedback. Would you agree that scenarios 1 and 2 should have similar CollisionImpulse values? At the very least, the value shouldn't vary by 300%. –  Aug 25 '16 at 15:23

0 Answers0