Discuss Scratch

Kuro_Pi
Scratcher
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?:
pointtowardsplayermove5steps
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.
deck26
Scratcher
1000+ posts

Changing X and Y VARIABLES

changexbychangeyby
Kuro_Pi
Scratcher
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:
xpositionPlayerXposition
asivi
Scratcher
1000+ posts

Changing X and Y VARIABLES

Kuro_Pi wrote:

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:
xpositionPlayerXposition
I suppose you aren't explaining your case right.
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
setplayer X positiontoxpositionsetplayer Y positiontoyposition
jokebookservice1
Scratcher
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

defineifyouwanttomovethismanystepschangeX Variablebysinofdirection*thischangeY Variablebycosofdirection*this

Last edited by jokebookservice1 (June 9, 2016 15:39:26)

xc46
Scratcher
99 posts

Changing X and Y VARIABLES

jokebookservice1 wrote:

Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already) me being a bit hypocrytical there

defineifyouwanttomovethismanystepschangeX Variablebycosofdirection*thischangeY Variablebysinofdirection*this
The list of block workarounds says that you should switch your sin and cos.

Last edited by xc46 (June 9, 2016 11:20:48)

deck26
Scratcher
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.
asivi
Scratcher
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?

Last edited by asivi (June 9, 2016 11:58:21)

jokebookservice1
Scratcher
1000+ posts

Changing X and Y VARIABLES

xc46 wrote:

jokebookservice1 wrote:

Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already) me being a bit hypocrytical there

defineifyouwanttomovethismanystepschangeX Variablebycosofdirection*thischangeY Variablebysinofdirection*this
The list of block workarounds says that you should switch your sin and cos.
Then I will edit my post
Kuro_Pi
Scratcher
62 posts

Changing X and Y VARIABLES

deck26 wrote:

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

Changing X and Y VARIABLES

Kuro_Pi wrote:

deck26 wrote:

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.
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.
Use trig then

jokebookservice1 wrote:

Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already) me being a bit hypocrytical there

defineifyouwanttomovethismanystepschangeX Variablebysinofdirection*thischangeY Variablebycosofdirection*this
(Maybe you need to swap the sin and cos over IF it doesn't work)
Kuro_Pi
Scratcher
62 posts

Changing X and Y VARIABLES

asivi wrote:

Kuro_Pi wrote:

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:
xpositionPlayerXposition
I suppose you aren't explaining your case right.
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
setplayer X positiontoxpositionsetplayer Y positiontoyposition

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
Scratcher
62 posts

Changing X and Y VARIABLES

jokebookservice1 wrote:

xc46 wrote:

jokebookservice1 wrote:

Perhaps you want this? (But I'd recommend covering trig in school first (if you haven't already) me being a bit hypocrytical there

defineifyouwanttomovethismanystepschangeX Variablebycosofdirection*thischangeY Variablebysinofdirection*this
The list of block workarounds says that you should switch your sin and cos.
Then I will edit my post

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
Scratcher
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
Scratcher
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!
Kuro_Pi
Scratcher
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/
jokebookservice1
Scratcher
1000+ posts

Changing X and Y VARIABLES

Kuro_Pi wrote:

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!
Yeah, I already edited my original post, but accidentally quoted a quote.
UnlinedBus
Scratcher
14 posts

Changing X and Y VARIABLES

xygotox:xy:y
deck26
Scratcher
1000+ posts

Changing X and Y VARIABLES

UnlinedBus wrote:

xygotox:xy:y
Please don't necropost.
UnlinedBus
Scratcher
14 posts

Changing X and Y VARIABLES

changexbyroundx

Powered by DjangoBB