Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » I need help with a simple rotating script.
- plopa1
- Scratcher
17 posts
I need help with a simple rotating script.
So, I want to make a rotating script. I want it to tilt to the left, then smoothly start tilting to the right. This is my current script. It's pretty long and also its not very smooth.
and then the same thing but it turns in the diffrent direction. Heres the link to my game: https://scratch.mit.edu/projects/608595293/
There's already a rotating script but I want it to be smoother and also rotate a little less.
Thanks in advance!
when green flag clicked
forever
turn cw (1) degrees
wait (0.1) secs
turn cw (2) degrees
wait (0.1) secs
turn cw (3) degrees
wait (0.5) secs
turn ccw (2) degrees
wait (0.1) secs
turn ccw (2) degrees
end
and then the same thing but it turns in the diffrent direction. Heres the link to my game: https://scratch.mit.edu/projects/608595293/
There's already a rotating script but I want it to be smoother and also rotate a little less.
Thanks in advance!
- plopa1
- Scratcher
17 posts
I need help with a simple rotating script.
Oh, and also, I forgot the last block in the forever loop
point in direction (0 v)
- MrNanners
- Scratcher
100+ posts
I need help with a simple rotating script.
this'll be a lot smoother
when green flag clicked
point in direction (0 v)
repeat (12)
turn cw (0.34) degrees
end
forever
repeat (24)
turn ccw (0.34) degrees
end
repeat (24)
turn cw (0.34) degrees
end
That's about it, see yah.
My best and most helpful projects:
Savable Games Engine | Plants Vs. Zombies | Competitive Clicker Game
As a kid, John Lennon, member of the most successful band in history, the Beatles, said, “When I grow up, I want to be happy.” The teachers around him said that he didn't understand the question, but young John said that {the teachers} didn't understand life.
- Konserverad_gran
- Scratcher
70 posts
I need help with a simple rotating script.
Sine functions tend to be really smooth. I'd probably try something like this:
This will start to the right. If you want it to begin by tilting left, you can set the max angle negative.
set [t0 v] to (timer)
forever
point in direction ((max angle) * ([sin v] of ((speed) * ((timer) - (t0)))))
end
This will start to the right. If you want it to begin by tilting left, you can set the max angle negative.
- tank401
- Scratcher
29 posts
I need help with a simple rotating script.
Try this:
change speed variable for speed of rotating
when green flag clicked
forever
change [Speed v] by (5)
point in direction (((([sin v] of (Speed v)) * (8)) + (90)) v)
end
change speed variable for speed of rotating
- plopa1
- Scratcher
17 posts
I need help with a simple rotating script.
Thank you so much! That really helped me. I have no idea how to use this block/every option there is
([floor v] of (9))
- MrNanners
- Scratcher
100+ posts
I need help with a simple rotating script.
Thank you so much! That really helped me. I have no idea how to use this block/every option there is
([abs v] of (x)) // will always return the NUMERICAL DISTANCE FROM ZERO, and will ALWAYS BE POSITIVESin, Cos, and Tan are all Trigonometric Functions used mainly to find missing triangle lengths. I have a video here that'll hopefully do a good job explaining for you. I also made you a graph for you to visualize and easily calculate each of the Trig Functions. I personally have never used these for coding.
([abs v] of (9.3)) // will always return 9.3 and
([abs v] of (-9.8)) // will always return 9.8 as well
([floor v] of (x)) // means that it will always ROUND DOWN so
([floor v] of (9.3)) // will return 9 and
([floor v] of (9.8)) // will return 9 as well
([ceiling v] of (x)) // means that it will always ROUND UP so
([ceiling v] of (9.3)) // will return 10 and
([ceiling v] of (9.8)) // will return 10 as well
([sqrt v] of (x)) // will return a REAL POSITIVE SQUARE ROOT which means that it will return a value that, when multiplied by itself, will be equal to X, but it will always return the positive variant.
([sqrt v] of (9)) // will always return 3 and not -3 because -3 is NEGATIVE
([sqrt v] of (-9)) // will return NaN because the answer is a NON-REAL NUMBER
([sin v] of (x)) ([cos v] of (x)) ([tan v] of (x))
([asin v] of (x)) ([acos v] of (x)) ([atan v] of (x))Asin, Acos, and Atan are all Trigonometric Functions used mainly to find missing triangle angles. Once again, I have a video here that'll hopefully do a good job explaining for you. I also made you a graph for you to visualize and easily calculate each of the Trig Functions. I personally have only ever used atan for calculating the direction I need to face to point to certain coordinates
([log v] of (x)) ([ln v] of (x))Logarithms (log) and Natural Logarithms are very similar in what they do. They are best described as logBASE(x). The difference between these two functions is the “BASE”. In “log”, BASE equals 2, and in “ln” BASE equals ~2.72182. Logarithms are the opposite of exponents, and so they figure out how many times you have to multiply “BASE” by itself to get “x”. For example:
([log v] of (8)) // will return 3 because you multiply 2 by itself 3 times (2*2*2) in order to get 8This multiply 10 by itself the same amount of times as x. If the number is an INTEGER (meaning that is has no decimal, e.g. 1, 2, 4, & 12), then the integer will tell you how many zeros follow the one, or if it is a negative number, how many zeros are in the return value. For example:
([ln v] of (20.0855369232)) // will return ~3 because you multiply 2.72182 by itself ~3 times (2.72182*2.72182*2.72182) to get 20.0855369232
([e ^ v] of (x)) // is the opposite of natural logarithms. "e" is always equal to ~2.72182, and so x is how many times you are multiplying e by itself.
([e ^ v] of (3)) // will always return ~20.0855369232 because (e*e*e) equals ~20.0855369232
([e ^ v] of (0)) // will always return 1 because anything to the power of 0 equals 1.
([10 ^ v] of (x))
([10 ^ v] of (4)) // will always return 10000. Notice how there are 4 zeros.
([10 ^ v] of (-1)) // will always return 0.1. Notice there is only 1 zero.
([10 ^ v] of (-4)) // will always return ~0.0001. Notice how there are 4 zeros.
([10 ^ v] of (0)) // will always return 1. This is because anything to the power of 0 equals 1.
And that is the entirety of highschool math for you, hopefully this helped
That's about it, see yah.
My best and most helpful projects:
Savable Games Engine | Plants Vs. Zombies | Competitive Clicker Game
As a kid, John Lennon, member of the most successful band in history, the Beatles, said, “When I grow up, I want to be happy.” The teachers around him said that he didn't understand the question, but young John said that {the teachers} didn't understand life.
- plopa1
- Scratcher
17 posts
I need help with a simple rotating script.
Wow! Thanks a lot!
I'll probably be using that block a lot more now!
I'll probably be using that block a lot more now!
- mazzadoobry
- Scratcher
100+ posts
I need help with a simple rotating script.
As said above, using sine and cosine are very smooth.
I like scratch.
I would never say
I don't like scratch.
Lol read from top to bottom, then bottom to top.
window.document.getElementById(“follow-button”).addEventListener(click, clicked)
function clicked() {
console.log(“Thank you!”)
alert(“Lol”)
}
CANVAS IS A CONTAINER FOR GRAPHICS
- Discussion Forums
- » Help with Scripts
- » I need help with a simple rotating script.