I want to create a realistic spring object, as a sprite, that compresses and expands when a force is applied and released, respectively. The only thing I know is that it requires some complex animation, but have no idea how to do it. I'm using the Unity engine, but otherwise, it is a general question.
-
\$\begingroup\$ To what complexity would you like to simulate the spring? The most basic one involves using a spring coefficient and drawing some loops, more complex ones involve the material of the spring and the size of it (wire length, height, diameter) and compute the momentum of the spring (it makes it wobbly) \$\endgroup\$– BálintMar 20, 2017 at 12:15
-
\$\begingroup\$ You probably wouldn't want to use a sprite for this, but a line. \$\endgroup\$– BálintMar 20, 2017 at 12:18
-
\$\begingroup\$ Not very complex, just the basic stuff as shown in the figure. How would a line be used and look realistic? \$\endgroup\$– codeitMar 20, 2017 at 12:44
-
\$\begingroup\$ Springs are basically wires in a looped shape. I'll probably post an answer, wich involves makimg the lines go around an arc \$\endgroup\$– BálintMar 20, 2017 at 12:48
-
\$\begingroup\$ Thank you. I would request you to please help me on this issue. \$\endgroup\$– codeitMar 20, 2017 at 12:57
1 Answer
You might be over-complicating the problem. It sounds like you're really looking for a spring that does the following 3 things:
- Compresses
- Springs upwards
- Springs upwards and sideways
Try using three simple animations and some simple code to recognise when each should happen. With a nice animation that springs up and wobbles both ways when horizontal pressure is applied, that covers both directions, and the down and up are simple enough.
This would take far less work, and make the solution much more reliable and less prone to error.
-
2\$\begingroup\$ This seems more of a comment, but far more useful than your previous answer (both came up in the review queue). I have removed the specific commentary (answers are not a place for seeking clarification from the author). Perhaps you could elaborate on such code? Perhaps provide some pseudo-code? \$\endgroup\$– GnemlockApr 27, 2017 at 7:27