Discuss Scratch

-JS_Test-
Scratcher
53 posts

Abstract question regarding "shaking"

Hello everyone,

I'm making a game where the ground shakes periodically. The way that the ground shakes is determined by two variables: EARTHQUAKE X and EARTHQUAKE Y.

the code goes:

set [EARTHQUAKE X] to (pick random (-10) to (10))
set [EARTHQUAKE Y] to (pick random (-10) to (10))
change x by (EARTHQUAKE X)
change y by (EARTHQUAKE Y)

all of this inside a loop for obvious reasons.

Problem is, the ground usually drifts away too much from its original position.

I, therefore, am looking for a way to “randomize without really randomizing” this shake. Here's what I mean:
If the previous “earthquake x”, for example, had a negative value, the odds of earthquake x having ANOTHER negative value once the loop loops is < 50%.

If you want, the link to the game is https://scratch.mit.edu/projects/970829022/

This code can be found within the “level” sprite.

IMPORTANT! It will be really easy to evaluate what the previous value for “earthquake x” was, as this value will be stored inside the ground's y position.

Last edited by -JS_Test- (Feb. 24, 2024 18:40:14)

RethinkingVoxels
Scratcher
1000+ posts

Abstract question regarding "shaking"

You could try checking if it's negative, change the positive value of the pick random block to be 5?

Last edited by RethinkingVoxels (Feb. 24, 2024 18:45:29)

sashimiricedev
Scratcher
100+ posts

Abstract question regarding "shaking"

Rather than changing the x, you set an offset. Something Like this:
go to x: ((my X) + (Earthquake X)) y: ((my Y) + (Earthquake Y))
My X and My Y would contain the player or the level's real X and Y
This way it is literally impossible for anything to go outside the pick random's bounds

Last edited by sashimiricedev (Feb. 24, 2024 19:24:38)

Powered by DjangoBB