Mihai Fratu
Mihai Fratu

Reputation: 7663

How to create a soft body in SceneKit

So.

After many years of iOS development I said it's time to try to do a little game for myself. Now I chose to do it using Apple's SceneKit since it looks like it provides everything I need.

My problem is that I've stumbled upon a huge problem (for me) and searching on Google doesn't yeld any results.

Any idea how do I go about having an object (a sphere for that matter) that deforms itself, say, because of a gravitational force. So basically it should squash on impact with the ground.

Or, how do I go about deforming it when it collides with other spheres, like a soft beach ball would?

Any starting point along those lines would be helpful.

I can post my code here, but I'm afraid it has nothing to do with my problem since I really don't know where to start.

Thanks!

Update

After doing a bit more reading I think that what I want could be doable with Vertex Shaders. Is that a right path to follow?

Upvotes: 1

Views: 1308

Answers (2)

Hal Mueller
Hal Mueller

Reputation: 7646

For complicated animations, you'll generally be better off using a 3D modeling tool like Blender, Maya, or Cheetah3D to build the body and construct the animation. Those tools let you think at a higher level of abstraction. Then you can export that model to Collada (DAE) format and then import it into SceneKit.

https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Basic_Animation/Bounce has a tutorial on building a deforming, bouncing ball using Blender.

Upvotes: 1

Craig Siemens
Craig Siemens

Reputation: 13276

SceneKit only does physics using rigid bodies. If you want something to deform, you would have to do it yourself.

It is probably because SceneKit has no way of knowing how an object should be deformed. Should it just compress, should it compress in one direction and expand in all others to preserve it's volume, should only part of the model compress and the rest stay rigid (like the tires on a car).

What you could try is wait for a collision to occur and do the following

calculate and store the velocity after the bounce
disable collision checking on the object
run an animation for the "squash"
enable collision checking on the object
apply the calculated velocity

It will be entirely up to you how real or cartoony you want to make the bounce look.

Upvotes: 0

Related Questions