Jelly Sprites is a soft-body physics system for Unity sprites, It allows you to quickly and easily convert static sprites into ones that will bounce, stretch and deform, naturally reacting to physical forces in your game.

Wednesday 12 February 2014

Manually Moving a Jelly Sprite

I was recently asked how to manually move a Jelly Sprite after the game had started. This isn't entirely trivial - you will find that you can't simply modify the Jelly Sprite's position (either by dragging it in the scene view or by modifying its transform in code), as it will immediately reset itself back to its previous position.

The reason for this is that each Jelly Sprite is composed of lots individual physics bodies (known as 'Reference Points'), which are used to determine how the Jelly Sprite should move and deform. These Reference Points are kept separate from the Jelly Sprite GameObject, which is automatically updated each frame to match the position of the central Reference Point (the rest of the Reference Points are used to calculate how to deform the mesh). Therefore, if you want to move the Jelly Sprite, you actually need to move the Reference Points, not the sprite itself.

If you're doing this in the scene view, just look for a GameObject called something like 'xxx Reference Points' (with 'xxx' being the name of the original Jelly Sprite GameObject) - you can move this to move move the Reference Points, and the sprite will follow.

I've also written a bit of code that will move a Jelly Sprite to a given position by altering the position of its Reference Points - hopefully this is of use to some people! I'll make sure that I include it in the next update as a SetPosition() function.

No comments:

Post a Comment