Recently I created an effect for my game, Visual Out, that I’m pretty happy with. I had some wire assets that were static images, that I wanted to animate when the player touched them.
There are a number of ways I could have done this – including manual animations, or physics objects, but I wanted a simpler method that didn’t involve physics calculations.
The method I decided upon used a Skew effect to bend the end of the sprite. This only affects the image, so if I wanted to attach something to the bent end, it would look offf, but it works for simple hanging items like wires and vines. Construct 2 doesn’t come with a Skew effect built in (I have no idea why) so I had to find a third-party effect to use. I used this one.
I gave the wire sprite the Skew effect, but then I had to make it move. For this, I used a Sine behavior, with the “Movement” parameter set to “Value” so that the Sine wave didn’t affect the position of the object, and just saved its magnitude as a value. In the event sheet, I set the Skew effect’s parameter to the Sine behavior’s Value every tick, causing the skew to move.
Now I had a wire that swung back and forth nicely, but it didn’t react to the player. I did that by setting the Sine behavior’s magnitude (which was saved as it’s Value). I wanted the wire to start hanging straight down, so I set its magnitude to 0. When the player touches the wire, I set its magnitude to 20, and now it starts swinging. To simulate the effect of the wire losing momentum, I simply subtracted 1 from the Magnetude every 0.5 seconds, slowly reducing it back to zero, and causing it to hang still again.
I did have to change the Sine behavior’s Cycle Position depending on the direction the player hit the wire from – it wouldn’t make sense for the player to jump into the wire, and then the wire swing towards the player. So if the player hits the wire from the right (moving left), I set the cycle position to 0.5 – halfway through the cycle so instead of swinging right first, it swings left.
And that’s it! That’s how I created a simple hanging wire effect without using physics.