Discuss Scratch

RobsDobsScratch
New Scratcher
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!
vcokltfre
Scratcher
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
New Scratcher
4 posts

Scratch seems to not realize x coordinates

vcokltfre wrote:

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
I have shared it now.
PutneyCat
Scratcher
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
Scratcher
1000+ posts

Scratch seems to not realize x coordinates

In Figur1, I find
when green flag clicked
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]
The
<(x position) > (-300)>
should be
<(x position) < (-278)>
.

In Heli 2, I find
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
point in direction ((90) + ((5) * (Tempo::variables)))
change y by (Tempo::variables)
end
broadcast [Game Over! v]
Below the
if <key [up arrow v] pressed?> then
change [Tempo v] by (0.5)
end
there should be another if…then to make the helicopter descend if the down key is pressed:
if <key [down arrow v] pressed?> then
change [Tempo v] by (-0.5)
end
to make
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
Scratcher
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:

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
Scratcher
1000+ posts

Scratch seems to not realize x coordinates

timhortonsyo wrote:

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.
Do not remove this block.
timhortonsyo
Scratcher
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
New Scratcher
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.

Powered by DjangoBB