Discuss Scratch
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
So you know the way a sprite's coordinates are easily edited depending on direction, by doing something like this?:
As in, the EXCACT same amount.
The blocks above change the X and Y COORDINATES on a sprite. However, is there a way to change X and Y VARIABLES by the same amount?
As in, the EXCACT same amount.
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
Obviously I'd be changing the X and Y variables (not coordinates), but how would I change them by EXACTLY the same amount as how the coordinates would change?
The part where it points towards the player can be anywhere from 0-360 degrees, meaning the coordinates could be changed by a very specific number, possibly with multiple decimals. Is there a formula that you can use to find out what it would change by?
These are two different things:
The part where it points towards the player can be anywhere from 0-360 degrees, meaning the coordinates could be changed by a very specific number, possibly with multiple decimals. Is there a formula that you can use to find out what it would change by?
These are two different things:
- asivi
-
1000+ posts
Changing X and Y VARIABLES
variables (not coordinates), but how would I change them by EXACTLY the same amount as how the coordinates would change?I suppose you aren't explaining your case right. Obviously I'd be changing the X and Y
The part where it points towards the player can be anywhere from 0-360 degrees, meaning the coordinates could be changed by a very specific number, possibly with multiple decimals. Is there a formula that you can use to find out what it would change by?
These are two different things:
The coordinates for the player are those that the xposition and yposition reporters returns, so
change them by EXACTLY the same amount as how the coordinates would change
- jokebookservice1
-
1000+ posts
Changing X and Y VARIABLES
Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already) me being a bit hypocrytical there
Last edited by jokebookservice1 (June 9, 2016 15:39:26)
- xc46
-
99 posts
Changing X and Y VARIABLES
me being a bit hypocrytical thereThe list of block workarounds says that you should switch your sin and cos. Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already)
Last edited by xc46 (June 9, 2016 11:20:48)
- deck26
-
1000+ posts
Changing X and Y VARIABLES
I'm baffled as to what you mean. You want them to change by the same amount but don't just want to use change (whether change x by or change variable by) on the corresponding variables. Irt doesn't matter that much whether it's the built-in x and y or your own variables.
I suspect you don't mean by the same amount which automatically give you a fixed angle rather than pointing towards something.
If you want to know how much x and y would be changed by a move of length L in direction D then you need to use trigonometry as others have said.
I suspect you don't mean by the same amount which automatically give you a fixed angle rather than pointing towards something.
If you want to know how much x and y would be changed by a move of length L in direction D then you need to use trigonometry as others have said.
- asivi
-
1000+ posts
Changing X and Y VARIABLES
Maybe that you are a player in an scrolled map (which it is moving already) but yo can go off-screen?
Or perhaps you want as a player that the map would be scrolled when you reach the screen edges?
Or perhaps you want as a player that the map would be scrolled when you reach the screen edges?
Last edited by asivi (June 9, 2016 11:58:21)
- jokebookservice1
-
1000+ posts
Changing X and Y VARIABLES
Then I will edit my postme being a bit hypocrytical thereThe list of block workarounds says that you should switch your sin and cos. Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already)

- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
It's that I have a top-down game where the enemy's location is stored, so I want the stored location on the map to change, but not the on-screen location, as that's going to depend on it's position relative to the player. I'm baffled as to what you mean. You want them to change by the same amount but don't just want to use change (whether change x by or change variable by) on the corresponding variables. Irt doesn't matter that much whether it's the built-in x and y or your own variables.
I suspect you don't mean by the same amount which automatically give you a fixed angle rather than pointing towards something.
If you want to know how much x and y would be changed by a move of length L in direction D then you need to use trigonometry as others have said.
- jokebookservice1
-
1000+ posts
Changing X and Y VARIABLES
Use trig thenIt's that I have a top-down game where the enemy's location is stored, so I want the stored location on the map to change, but not the on-screen location, as that's going to depend on it's position relative to the player. I'm baffled as to what you mean. You want them to change by the same amount but don't just want to use change (whether change x by or change variable by) on the corresponding variables. Irt doesn't matter that much whether it's the built-in x and y or your own variables.
I suspect you don't mean by the same amount which automatically give you a fixed angle rather than pointing towards something.
If you want to know how much x and y would be changed by a move of length L in direction D then you need to use trigonometry as others have said.
me being a bit hypocrytical there(Maybe you need to swap the sin and cos over IF it doesn't work) Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already)
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
variables (not coordinates), but how would I change them by EXACTLY the same amount as how the coordinates would change?I suppose you aren't explaining your case right. Obviously I'd be changing the X and Y
The part where it points towards the player can be anywhere from 0-360 degrees, meaning the coordinates could be changed by a very specific number, possibly with multiple decimals. Is there a formula that you can use to find out what it would change by?
These are two different things:
The coordinates for the player are those that the xposition and yposition reporters returns, sochange them by EXACTLY the same amount as how the coordinates would change
The same thing goes here. I want the variables to be a stored position on the map (spanning much more than a single screen) and the coordinates are set based off how close/far the variables are from the player's.
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
Then I will edit my postme being a bit hypocrytical thereThe list of block workarounds says that you should switch your sin and cos. Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already)
I'll try that.
Also, I haven't covered trig (which I assume is trigonometry) yet.
Last edited by Kuro_Pi (June 9, 2016 18:35:35)
- jokebookservice1
-
1000+ posts
Changing X and Y VARIABLES
I haven't either, it shouldn't effect anything, and yeah, trigonometry isn't a word I like to keep typing up :P
Last edited by jokebookservice1 (June 9, 2016 18:37:27)
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
Well, turns out ‘sin’ should be used for X, and ‘cos’ for Y, but other than that, thank you so much! 
I don't know what either of those do, so I couldn't have figured that out myself. Thanks!

I don't know what either of those do, so I couldn't have figured that out myself. Thanks!
- Kuro_Pi
-
62 posts
Changing X and Y VARIABLES
And if you're curious, here's the link to the unfinished project, so maybe you'll understand my problem more
(the red arrow on the minimap represents the enemy) : https://scratch.mit.edu/projects/112702288/
(the red arrow on the minimap represents the enemy) : https://scratch.mit.edu/projects/112702288/
- jokebookservice1
-
1000+ posts
Changing X and Y VARIABLES
Yeah, I already edited my original post, but accidentally quoted a quote. Well, turns out ‘sin’ should be used for X, and ‘cos’ for Y, but other than that, thank you so much!
I don't know what either of those do, so I couldn't have figured that out myself. Thanks!