Page 1 of 1

[Solved] Shake/Vibrate Sprite

Posted: Wed May 16, 2018 12:49 pm
by Semicolonkid
Hello!
I'm trying to figure out a way to make a character sprite shake/vibrate around in place to represent frustration or quivering in fear.
I dug around for an answer and found this, and added vertical movement to get this:

Code: Select all

transform shake:
    linear 0.090 xoffset -10
    linear 0.090 xoffset +0
    linear 0.090 yoffset -10
    linear 0.090 yoffset +0
    repeat
It's close, but it's not quite what I'm after. The sprite will move left, right, up, down, repeat, drawing a "corner" shape over and over. I want a more erratic shake in any direction.
I tried using Choice statements to break them up in various ways, but that usually just made the sprite move in a more robotic fashion (which admittedly was very cool and made me wish my story had sci-fi elements).

Any thoughts on how to achieve a more erratic look? Doesn't have to be random, as long as it looks like shaking on both the X and Y axis.

Re: Shake/Vibrate Sprite

Posted: Wed May 16, 2018 1:55 pm
by kivik
To start with, you can add multiple movements in the same linear statement:

Code: Select all

transform shake:
    linear 0.090 xoffset -10 yoffset -10
    linear 0.090 xoffset +10 yoffset +10
    repeat
I'm not very familiar with shaking effects, but I think randomising which direction / corner your image will move towards will always create weird effects - because a shake should always orbit a centre point or it's not a shake anymore. So if it starts top left it needs to go bottom right and back to top left. Of course you don't have to pass the centre point and but move in the general opposite direction at a slight angle shift - but I suspect this is too much work for what it's worth.

One thing you can do to randomise it is just how far the shakes go. This thread shows how to create a function to be used within a transform that achieves that: but you'll want a condition to toggle between top left and bottom right (if that's the direction you want to go for) in scale, so if you've just gone for bottom right (renpy.random.randint(5, 10) then the next set should be renpy.random.randint(-10, -5).

Hope that helps?

Re: Shake/Vibrate Sprite

Posted: Wed May 16, 2018 2:36 pm
by Semicolonkid
kivik wrote: Wed May 16, 2018 1:55 pm Hope that helps?
Yeah! You make a good point about the randomness, and you're right that moving on two axes in one statement is necessary for this effect.
After some experimenting, I've found something I'm quite pleased with:

Code: Select all

transform shake(rate=0.090):
    linear rate xoffset 2 yoffset -6
    linear rate xoffset -2.8 yoffset -2
    linear rate xoffset 2.8 yoffset -2
    linear rate xoffset -2 yoffset -6
    linear rate xoffset +0 yoffset +0
    repeat
Basically, I worked out the rough coordinates that a 5-pointed star has, and tried to draw the shape over and over.
I further tried randomizing the distance, but with values as low as these, it wasn't very noticeable. The one augmentation I would consider further would be adding a "strength" argument that's multiplied with all the offsets, defaulting to 1.

So, problem solved! Thanks!