1
votes

I have 10 square nodes with square physics bodies in a row. How can I best merge these physics bodies to create a single skphysicsbody?

The reason I need to do this is that a square object traveling on top of the square row "trips" at random. If I replace the 10 square nodes with a single rectangle, there's no "tripping" behavior.

My current best guess is this:

Create a superset rectangle, then use SKPhysicsBody(edgeChainFromPath:). Then create a node just for physics and add position it somehow in the scene. In more complex scenarios I'll have all sorts of different polygons in two dimensions, so I'm not sure how I would position the physics node.

Is there a better way? If not, how do I position the physics node?

2
The square that travels on top, I assume is using some friction to create the trip. Could you fake this top square's physicsBody (purely for the purposes of motion along the row of squares), making it a circle, so it rolls along, yet uses the square shape for drawing and contact purposes?Confused
@Confused Maybe! Like a child node that doesn't rotate for contact and the main physics node being a circle. I did notice that fixed the tripping, but the hitbox wasn't right for collision purposes. I'd need to shrink the circle to fit within the contact hitbox so it looked right but that could work.Stefan Kendall

2 Answers

0
votes

While not the answer to the question, using multiple physics bodies works great. My main issue is a rectangle sliding across rectangles. Using a non-visible circle removes the issue of rectangles tripping on each other entirely.

Thanks to @Confused in the comments.

0
votes

You can make a body of bodies with SKPhysicsBody(bodies:[SKPhysicsBody])

https://developer.apple.com/reference/spritekit/skphysicsbody/1519736-init