Discuss Scratch

daveh0
New Scratcher
2 posts

Calculate and apply realistic velocities when animating sprites

I am relatively new to Scratch (and animation in general) and have been playing around with various techniques I feel will probably come in handy. My project in question can be viewed at https://scratch.mit.edu/projects/109818118/#editor. It started as a basic, infinitely scrolling background and a sprite (in this case a dragon) with a fixed position… the scrolling of the background gives the illusion that it is the dragon that is moving. This proved to be relatively simple so I attempted to add in the complexity of increasing and decreasing (more accurately, reverting) the velocity of the dragon. This was done through adjusting the speed at which the background is scrolled as well as adjusting the dragon's position along the X axis.

My intent for both the background and the dragon itself was control the “speed” with the number of units (pixels, I would imagine) its position was adjusted by at a time.

I wanted to simulate an an exponential rate of acceleration and deceleration, as opposed speeding up and slowing down uniformly, so my goal was to start with a base number of units and increment or decrement accordingly. This is where I think I went wrong… or maybe I didn't.

I feel like there should be a cleaner set of numbers/calculations that can be used to determine and set the number of pixels to adjust each by, but I'm finding myself at a loss. Am I on the right track?
cs370705
New Scratcher
8 posts

Calculate and apply realistic velocities when animating sprites

daveh0 wrote:

I am relatively new to Scratch (and animation in general) and have been playing around with various techniques I feel will probably come in handy. My project in question can be viewed at http://scratch.mit.edu/projects/109818118/ . It started as a basic, infinitely scrolling background and a sprite (in this case a dragon) with a fixed position… the scrolling of the background gives the illusion that it is the dragon that is moving. This proved to be relatively simple so I attempted to add in the complexity of increasing and decreasing (more accurately, reverting) the velocity of the dragon. This was done through adjusting the speed at which the background is scrolled as well as adjusting the dragon's position along the X axis.

My intent for both the background and the dragon itself was control the “speed” with the number of units (pixels, I would imagine) its position was adjusted by at a time.

I wanted to simulate an an exponential rate of acceleration and deceleration, as opposed speeding up and slowing down uniformly, so my goal was to start with a base number of units and increment or decrement accordingly. This is where I think I went wrong… or maybe I didn't.

I feel like there should be a cleaner set of numbers/calculations that can be used to determine and set the number of pixels to adjust each by, but I'm finding myself at a loss. Am I on the right track?
VicTwenty
Scratcher
83 posts

Calculate and apply realistic velocities when animating sprites

When you accelerate you multiply by 1.05 (aCel) but when you decelerate, you are decelerating at a constant rate, instead, subtracting the amount each time

change [ velocityX] by (dCel)

See what it looks like when you multiply velocityX by 0,95 instead.

set [ velocityX] to [((velocityX) * (0.95)) ]

But it looks pretty nice how it is (although if the dragon flapped faster when it went faster that would be nice).

Last edited by VicTwenty (May 16, 2016 21:19:01)

glowmouse
Scratcher
4 posts

Calculate and apply realistic velocities when animating sprites

I've been playing with something that is kind of similar (my first scratch game). https://scratch.mit.edu/projects/109750373/

My rocket accelerates when you hold the up arrow. I added a drag to slow it down - the drag simply multiplies the velocity by a constant.
daveh0
New Scratcher
2 posts

Calculate and apply realistic velocities when animating sprites

VicTwenty wrote:

When you accelerate you multiply by 1.05 (aCel) but when you decelerate, you are decelerating at a constant rate, instead, subtracting the amount each time

change [ velocityX] by (dCel)

See what it looks like when you multiply velocityX by 0,95 instead.

set [ velocityX] to [((velocityX) * (0.95)) ]

But it looks pretty nice how it is (although if the dragon flapped faster when it went faster that would be nice).


Thanks for the response. I've added in the faster wing speed in my current version.

Since the value of velocityX is getting smaller with every iteration, changing it by dCel units will also produce a smaller and smaller number each time, thus producing the deceleration effect I'm going for. I think… right?

Your suggestion did work too though.

Powered by DjangoBB