Domanda

I want to make a simple bridge builder game with Sprite Kit. But I can't find a way to see how much force is applied to an joint.

For example I want to destroy a joint when a car is too heavy while driving over the bridge a user constructed. Is there a (simple) way to do this with Sprite Kit?

È stato utile?

Soluzione

Simple-ish/simplistic approach:

There's the mass property of an SKPhysicsBody that you can use for this. It's calculated arbitrarily, based on the size of the physics body by default. If the car consists of multiple physics bodies joined together, you can iterate through them to sum up the mass of all its parts, then break the joint if the car is too heavy.

The harder way (just an idea):

If the car is falling onto the bridge or bouncing and you need more detail in the joint destruction, you could, for example, make use of calculating the kinetic energy the car has just before hitting the bridge - that's 0.5 * mass * velocity * velocity (you can get the final peak velocity from the velocity vector getter of the physics body just before it contacts the surface). Or use any other physics formula to your liking. :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top