Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Platformer
- Kingawesometk
-
Scratcher
43 posts
Platformer
Here's how you can implement camera following in Scratch 3.0 using the “move” block:
1. Create a new sprite and name it “camera”.
2. Click on the “Events” category and drag a “when green flag clicked” block to the camera sprite.
3. Click on the “Control” category and drag a “forever” block to the “when green flag clicked” block.
4. Click on the “Motion” category and drag a “set x to ( ) y to ( )” block to the “forever” block.
5. Click on the small “fx” button next to the x and y inputs of the “set x and y” block, and select “Variables” > “Make a variable”. Name the variable “main sprite x” and “main sprite y”.
6. Click on the “Data” category and drag a “set main sprite x to ( )” block to the “when green flag clicked” block. Set the value of the block to the x position of your main sprite.
7. Repeat step 6 for the y position of your main sprite.
8. To add some smoothing to the camera movement, click on the “Motion” category and drag a “set x to ((x + (main sprite x)) / 2) y to ((y + (main sprite y)) / 2)” block to the “forever” block. This block calculates the average position between the camera and the main sprite, which creates a smoother movement effect.
Here's an example code block that shows how to implement camera following in Scratch 3.0:
```
Replace “x position of main sprite” and “y position of main sprite” with the x and y position of your main sprite.
1. Create a new sprite and name it “camera”.
2. Click on the “Events” category and drag a “when green flag clicked” block to the camera sprite.
3. Click on the “Control” category and drag a “forever” block to the “when green flag clicked” block.
4. Click on the “Motion” category and drag a “set x to ( ) y to ( )” block to the “forever” block.
5. Click on the small “fx” button next to the x and y inputs of the “set x and y” block, and select “Variables” > “Make a variable”. Name the variable “main sprite x” and “main sprite y”.
6. Click on the “Data” category and drag a “set main sprite x to ( )” block to the “when green flag clicked” block. Set the value of the block to the x position of your main sprite.
7. Repeat step 6 for the y position of your main sprite.
8. To add some smoothing to the camera movement, click on the “Motion” category and drag a “set x to ((x + (main sprite x)) / 2) y to ((y + (main sprite y)) / 2)” block to the “forever” block. This block calculates the average position between the camera and the main sprite, which creates a smoother movement effect.
Here's an example code block that shows how to implement camera following in Scratch 3.0:
```
when green flag clicked
forever
set x to (x position of main sprite)
set y to (y position of main sprite)
set x to (((x position) + (main sprite x)) / (2))
set y to (((x position) + (main sprite y)) / (2))
Replace “x position of main sprite” and “y position of main sprite” with the x and y position of your main sprite.
- bsteichman
-
Scratcher
500+ posts
Platformer
oh sorry I thought you were asking a different question, my bad
Last edited by bsteichman (April 4, 2023 19:48:28)
- Kingawesometk
-
Scratcher
43 posts
Platformer
when green flag clicked
forever
if <> then
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((<<<<<<<<<<<<<<<<<<<<<[] > []> > []> > []> > []> = []> = []> = []> < []> < []> < []> < []> < []> < []> < []> < []> < []> < []> < []> < []> < []> < []> - (amog us)) - (yes)) - (do the hig)) - (then)) - (0)) - (0)) - (stuff?)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) / (0)) / (0)) / (0)) / (0)) / (0)) * (0)) * (0)) * (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) - (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0)) + (0))
end
end
- Discussion Forums
- » Help with Scripts
-
» Platformer