Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Scratch seems to not realize x coordinates
- RobsDobsScratch
-
4 posts
Scratch seems to not realize x coordinates
We have created a project (copied from a book) where you can fly a helicopter. Now it looks like the house is setting y-coordinates instead of defined x-coordinates. Link to project: https://scratch.mit.edu/projects/378524583/
The house should move slowly to the left but it doesn't. It just moves up and down. Also the helicopter moves just upwards but not downwards.
Can anyone help us and tell us what we've done wrong.
Thank you!
The house should move slowly to the left but it doesn't. It just moves up and down. Also the helicopter moves just upwards but not downwards.
Can anyone help us and tell us what we've done wrong.
Thank you!
- vcokltfre
-
100+ posts
Scratch seems to not realize x coordinates
You need to share your project if you want us to look at it, when you've shared it I'll take a look and see what's going on
- RobsDobsScratch
-
4 posts
Scratch seems to not realize x coordinates
I have shared it now. You need to share your project if you want us to look at it, when you've shared it I'll take a look and see what's going on
- PutneyCat
-
500+ posts
Scratch seems to not realize x coordinates
In the house sprite you have “if x position > -300” when I think you meant to have “if x position < -300”. Try changing “>” to “<”.
- mlcreater
-
1000+ posts
Scratch seems to not realize x coordinates
In Figur1, I find
In Heli 2, I find
when green flag clickedThe
go to x: (200) y: (-250)
repeat until <touching [Heli 2 v]>
change x by (-20)
if <(x position) > (-300)> then
go to x: (300) y: (pick random (-80) to (-280))
change [Punkte v] by (1)
end
end
broadcast [Game Over! v]
<(x position) > (-300)>should be
<(x position) < (-278)>.
In Heli 2, I find
when green flag clickedBelow the
...::grey
repeat until <touching [edge v]>
change [meine Variable v] by (-0.1)
if <key [up arrow v] pressed?> then
change [Tempo v] by (0.5)
end
point in direction ((90) + ((5) * (Tempo::variables)))
change y by (Tempo::variables)
end
broadcast [Game Over! v]
if <key [up arrow v] pressed?> thenthere should be another if…then to make the helicopter descend if the down key is pressed:
change [Tempo v] by (0.5)
end
if <key [down arrow v] pressed?> thento make
change [Tempo v] by (-0.5)
end
when green flag clicked
...::grey
repeat until <touching [edge v]>
change [meine Variable v] by (-0.1)
if <key [up arrow v] pressed?> then
change [Tempo v] by (0.5)
end
if <key [down arrow v] pressed?> then
change [Tempo v] by (-0.5)
end
point in direction ((90) + ((5) * (Tempo::variables)))
change y by (Tempo::variables)
end
broadcast [Game Over! v]
- timhortonsyo
-
31 posts
Scratch seems to not realize x coordinates
The helicopter is not moving down because it only has an “if up key is pressed” check. You'll want to copy-paste that check but change the input to the down key and change the variable to a negative, like so:
The house is spazzing out because a block is repeatedly telling it to set its y to a random value:
Because this block also tells the building to constantly set its x to 300, it can't move left. From the if block that controls this block, I can see this should only activate when it reaches the left side of the screen. Change the if condition to:
if <key [up arrow] pressed?> then
change [Tempo] by (0.5)
end
if <key [down arrow] pressed?> then
change [Tempo] by (-0.5)
end
The house is spazzing out because a block is repeatedly telling it to set its y to a random value:
go to x: (300) y: (pick random (-80) to (-280))
Because this block also tells the building to constantly set its x to 300, it can't move left. From the if block that controls this block, I can see this should only activate when it reaches the left side of the screen. Change the if condition to:
if <(x position) < [-297]> then
end
Last edited by timhortonsyo (March 22, 2020 16:17:45)
- mlcreater
-
1000+ posts
Scratch seems to not realize x coordinates
Do not remove this block. The house is spazzing out because a block tells it to set its y to a random value:go to x: (300) y: (pick random (-80) to (-280))Because this block also tells the building to constantly set its x to 300, it can't move left. Removing this block will make the building move left properly.
- timhortonsyo
-
31 posts
Scratch seems to not realize x coordinates
My bad, I didn't see that this was supposed to randomize the y coordinate of the building each time it reaches the left end. Edited my response
- RobsDobsScratch
-
4 posts
Scratch seems to not realize x coordinates
Thank you to all.
Project is fixed - we changed the variable name to “tempo” instead of “my variable” and changed > to < as suggested.
Project is fixed - we changed the variable name to “tempo” instead of “my variable” and changed > to < as suggested.
- Discussion Forums
- » Help with Scripts
-
» Scratch seems to not realize x coordinates