Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » question- how do you make a camera move with the player?
- Jill118
-
Scratcher
100+ posts
question- how do you make a camera move with the player?
um, the question is above… I'm making a new game but i don't know how to make the screen move along with the player while player moves. I need the script.
Huge thanks for anyone who's willing to help me
Jill118
Huge thanks for anyone who's willing to help me

Jill118
- deck26
-
Scratcher
1000+ posts
question- how do you make a camera move with the player?
So you're talking about scrolling - the screen is just a window onto the world of the game. So what you can see depends on the position of the window. The wiki includes pages on scrolling and these demos may help.
https://scratch.mit.edu/projects/304642094
https://scratch.mit.edu/projects/92682141
https://scratch.mit.edu/projects/304642094
https://scratch.mit.edu/projects/92682141
- mmhmBeans
-
Scratcher
500+ posts
question- how do you make a camera move with the player?
There are a few ways to do it. This is the simplest one, but it's not good at dealing with offscreen sprites, so you will likely have to make the map wrap around.
Create 2 variables: ‘Scroll X’ and ‘Scroll Y’.
Move the player like you would normally. The next part depends on whether you want the camera to be locked onto your player or to slide toward the player.
Use this method if you want the camera to be locked onto the player.
Use this method if you want the camera to slide toward the player smoothly.
Now, you need to move the other things on the scene. Make sure that the other sprites that will be scrolling are in a layer behind the player and put this code into them:
Create 2 variables: ‘Scroll X’ and ‘Scroll Y’.
Move the player like you would normally. The next part depends on whether you want the camera to be locked onto your player or to slide toward the player.
Use this method if you want the camera to be locked onto the player.
change [Scroll X v] by ((0) - (x position))
change [Scroll Y v] by ((0) - (y position))
go to x: (0) y: (0)
Use this method if you want the camera to slide toward the player smoothly.
change [Scroll X v] by (((0) - (x position)) * (0.1)) // increase '0.1' to increase the camera speed
change [Scroll Y v] by (((0) - (y position)) * (0.1))
change x by (Scroll X)
change y by (Scroll Y)
Now, you need to move the other things on the scene. Make sure that the other sprites that will be scrolling are in a layer behind the player and put this code into them:
when green flag clicked
forever
change x by (Scroll X)
change y by (Scroll Y)
- Jill118
-
Scratcher
100+ posts
question- how do you make a camera move with the player?
thanks both of you! all very useful
- WLATMAN
-
Scratcher
1 post
question- how do you make a camera move with the player?
is there a camera object? or do I put the script on the player object?
- ItBeJC
-
Scratcher
1000+ posts
question- how do you make a camera move with the player?
is there a camera object? or do I put the script on the player object?Please don't necropost; that is, post on old topics. Be sure to check the date of the first and most recent post in a topic. This one happens to be about 2 years old, so please create your own.
That being said, those scripts would probably be put into the level sprite (the sprite that represents your ground/platforms, whatever the player walks on). However, I'm not sure, as I would've approached the situation a bit differently.
- ma461273
-
Scratcher
73 posts
question- how do you make a camera move with the player?
Can you put in a collision detection script with the camera scrolling
- Scyth3d
-
Scratcher
500+ posts
question- how do you make a camera move with the player?
Can you put in a collision detection script with the camera scrollingyes but please stop necroposting/thread hijackinmg and make a new topic
- Discussion Forums
- » Help with Scripts
-
» question- how do you make a camera move with the player?