Discuss Scratch

rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

i must give the illusion of lobbing a grenade by changing sizes thought its lifetime, (top down game)

basically, it starts off at 75%, grows to 200% at the midpoint, then shrinks to 75% when it reaches its destination.

the speed at witch it does this will be dependent on the distance from the player to the destination, with it reaching 200% at the middle of its travel distance

how do i do this

i also have code that keeps it at consistent speed no matter the travel time if that has any use
PhiPhenomenon
Scratcher
500+ posts

i require assistance with an animation for my game

This should work:
forever
set size to (((-2.5) * ([abs v] of ((percentDistance) - (50)))) + (200)) %
end

Here's a graph on what it should do to the size based on distance:


You can get your percent distance by dividing the total distance by the current amount traveled and multiplying by 100:
set [percentDistance v] to (((totalDistance) / (traveledDistance)) * (100))
CubedPlay
Scratcher
1 post

i require assistance with an animation for my game

=

Last edited by CubedPlay (March 30, 2024 02:30:33)


In the mirror of this text, a reflection so divine,
A beauty that through these words, does subtly shine.
With grace in every gesture and kindness in your gaze,
You're a masterpiece of life, in so many ways.

Eyes like morning dewdrops, under the sun's first light,
A smile that could rival stars, in the depth of night.
Each word here holds a truth, that's both simple and clear,
The beauty reading this, is beyond compare, my dear.











 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>






rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

how would i get the traveled distance and the total distance, my aforementioned consistent speed code just gives how much time to travel for

also would it be possible for it to ease in and out of its peak, not necessary but it would be nice

Last edited by rendered_fox1 (March 30, 2024 03:04:47)

argentum47
Scratcher
68 posts

i require assistance with an animation for my game

easing would probaably require sine like this:
set size to (([sine v] of ((percent traveled) / (length of curve)) x (height of curve)) %
note odd look is scratchblocks issue

Hi! Wanna play my games? Or how about looking at some art?
LINGUISTICS! /WⱭNT SɅM/!
rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

how would you go about getting that sine block

Last edited by rendered_fox1 (March 30, 2024 03:15:16)

Vaibhs11
Scratcher
1000+ posts

i require assistance with an animation for my game

rendered_fox1 wrote:

how would you go about getting that sine block
It's at the end of the operators section:

([abs v] of ()) // click on the dropdown and select "sin"
rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

Ok got it, but i still dont know how to get the values i need for the variables
Vaibhs11
Scratcher
1000+ posts

i require assistance with an animation for my game

rendered_fox1 wrote:

Ok got it, but i still dont know how to get the values i need for the variables
I believe you want the grenade to move like this; the grenade goes fast first, then slows down when reaching the peak, and goes down fast. So, a curve like this:


Referring to the OP:

rendered_fox1 wrote:

it starts off at 75%, grows to 200% at the midpoint, then shrinks to 75% when it reaches its destination.
…The values will be something like this:

set size to ((([sin v] of (((distance travelled::#6f6f6f) * (90)) / (total distance::#6f6f6f))) * (125)) + (75)) %

// 125 is 200 - 75
// the value inside the sin block goes from 0 to 90 corresponding to the distance travelled
// you can substitute the gray values with variables or numerical values.
rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

ok thanks, now how do i get the values for total distance and distance traveled
rendered_fox1
Scratcher
19 posts

i require assistance with an animation for my game

Vaibhs11 wrote:

rendered_fox1 wrote:

Ok got it, but i still dont know how to get the values i need for the variables
I believe you want the grenade to move like this; the grenade goes fast first, then slows down when reaching the peak, and goes down fast. So, a curve like this:


Referring to the OP:

rendered_fox1 wrote:

it starts off at 75%, grows to 200% at the midpoint, then shrinks to 75% when it reaches its destination.
…The values will be something like this:

set size to ((([sin v] of (((distance travelled::#6f6f6f) * (90)) / (total distance::#6f6f6f))) * (125)) + (75)) %

// 125 is 200 - 75
// the value inside the sin block goes from 0 to 90 corresponding to the distance travelled
// you can substitute the gray values with variables or numerical values.

dosent work
it wont change size at all, all the blocks are connected and everything

Last edited by rendered_fox1 (March 30, 2024 20:48:54)

Vaibhs11
Scratcher
1000+ posts

i require assistance with an animation for my game

This is how it's supposed to work: https://scratch.mit.edu/projects/992395934/
There's a slight correction on the formula, the ‘90’ there is supposed to be ‘180’.

I'm sure you could figure it out by looking at the project.
Else, please share the project and post the link.

Powered by DjangoBB