Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need Help for coding Camera Movement
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
Hi,
I am making a car game and I am wondering how to code camera movement so that the camera view can follow the car.
Thank you!
I am making a car game and I am wondering how to code camera movement so that the camera view can follow the car.
Thank you!
- bcs320jn
-
100+ posts
Need Help for coding Camera Movement
What type is it? Top-down, etc.?
Last edited by bcs320jn (March 15, 2022 20:51:37)
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
I'm sorry, what is top-down? What type is it? Top-down, etc.?
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
It's a car race game and I want the camera to follow the car. It has loops and turns, not like a straight line.
- bcs320jn
-
100+ posts
Need Help for coding Camera Movement
Could you please provide a link to the project? That would make it a lot easier to understand.
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
The problem is that all I have in the project is the car design and the map. Do you just want the picture of the map?
- bcs320jn
-
100+ posts
Need Help for coding Camera Movement
No thanks, I do not need a picture of the map. I would suggest this for the code:
1: basic movement and camera following
*In the ‘map’ sprite, add a new (empty) costume. Name this ‘Blank’.
*Next, go to the ‘car’ sprite. Add this code in:
*Then, go back to the map sprite. Put in this code:
2: Adding boundaries
For this, you need to find the width and height of the ‘map’ costume. If you don't know how to get this, I will respond later with an answer.
For adding boundaries, put this code under the previous code:
1: basic movement and camera following
*In the ‘map’ sprite, add a new (empty) costume. Name this ‘Blank’.
*Next, go to the ‘car’ sprite. Add this code in:
This just allows you to control the direction of the car with the arrow keys.
*Then, go back to the map sprite. Put in this code:
This allows you to move forwards and backwards on the map.
2: Adding boundaries
For this, you need to find the width and height of the ‘map’ costume. If you don't know how to get this, I will respond later with an answer.
For adding boundaries, put this code under the previous code:
If this doesn't work in any way, please tell me.
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
Can you explain to me what adding boundaries is? And how to find the height and width of the map costume? snip
Last edited by Enigma_Ezra (April 27, 2022 16:46:37)
- bcs320jn
-
100+ posts
Need Help for coding Camera Movement
Boundaries being there so that the map goes off-screen if you go too far out.
- bcs320jn_test
-
13 posts
Need Help for coding Camera Movement
For the width and height, this project should help:
https://scratch.mit.edu/projects/659775075/
https://scratch.mit.edu/projects/659775075/
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
Okay, thank you! Also, my project doesn't use arrow keys, they use the direction of the mouse (including when backing up ). Also, the car can go when the mouse is down (so like the car can't move when the mouse is up). How do I change the code?
Last edited by Enigma_Ezra (March 15, 2022 23:55:39)
- bcs320jn_test
-
13 posts
Need Help for coding Camera Movement
First, replace the car code with this:
And in the map sprite, replace the
With
Last edited by bcs320jn_test (March 16, 2022 01:25:17)
- bcs320jn_test
-
13 posts
Need Help for coding Camera Movement
I made a little oopsie in the barriers code. I’ll fix it in the morning and tell you. (Sorry!)
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
I made a little oopsie in the barriers code. I’ll fix it in the morning and tell you. (Sorry!)
Okay, I just saw these in the morning anyway so I can wait.

- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
Got it! Thank you so much! snip
Last edited by Enigma_Ezra (April 27, 2022 16:47:26)
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
I can't put the boundaries code under a forever loop though… snip
Last edited by Enigma_Ezra (April 27, 2022 16:47:45)
- bcs320jn_test
-
13 posts
Need Help for coding Camera Movement
Sorry, put that under the code IN the forever loop
Last edited by bcs320jn_test (March 16, 2022 17:21:46)
- Enigma_Ezra
-
500+ posts
Need Help for coding Camera Movement
IN the forever loopOkay. Did you change the boundaries code yet? Sorry, put that under the code
Last edited by Enigma_Ezra (March 16, 2022 17:25:26)
- bcs320jn_test
-
13 posts
Need Help for coding Camera Movement
The code above was wrong. Here is the fixed version:
You'll have to look closely, because it was a small change. (Adding 240 or 180 to the boundaries limits)
Last edited by bcs320jn_test (March 16, 2022 17:33:38)
- Discussion Forums
- » Help with Scripts
-
» Need Help for coding Camera Movement