4
votes

I'm trying to write an iOS game with Spritekit and Swift and this is my first question on stackoverflow :)

To simplify my problem and my constraints, let's say I have two rectangle SKShapeNodes (my level) with the same height which are completely side by side, with physics bodies but non-dynamic. The hero is just a square SKShapeNode with a dynamic physics body which can move on top of those rectangles. The player uses the accelerometer to move the hero.

I'm not sure why, but sometimes, as the hero slides along the top of the rectangles, it stops right away at the gap between the two rectangles, or seems to be tripping over this gap (small jump over it) :((( The move should be smooth instead.

Is there a workaround to make the surface between the two rectangles more "flat"/smoother, knowing that I can't merge them for the purpose of the game?

(Things I've tried which didn't work: "floor" all dimensions, positions to closest Int values; make the hero physics body rounder; enable/disable precise collisions).

Thanks!

1
Welcome to StackOverflow. If possible, try to provide an image explanation (screenshot, gif, etc), so we can understand your problem better. Anyway, seems like a ghost vertice. Does your problem looks like the one on the link? - Tiago Marinho
Thanks Tiago! :) I believe this is exactly the same problem I have. I should be able to implement a workaround or learn more about this, thanks to you :) - nicognito
A common solution to this problem is to make the bottom of your hero's physics body circular. For example, you could create a physics body from a rectangle and a circle, and place the circle such that it just extends past the bottom of the hero. - Epic Byte

1 Answers

1
votes

The easiest fix for this issue is to create a circular physics body for the moving object instead of a rectangle. If needed, you can also combine 2 or more physics bodies to more accurately cover an object's height. See using (SKPhysicsBody *)bodyWithBodies:(NSArray *)bodies in the docs.

Combine 2 bodies with a circle at the bottom:

enter image description here