This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-18 18:58:08

Billybob-Mario
Scratcher
Registered: 2008-01-05
Posts: 500+

[Math] How to move in a direction without taking steps?

Edit: MathWizz gave me the solution! Thank you:

Solved problem:
I'm making a game that scrolls on the X and Y axis. It will have turrets that shoot at the player. The projectiles need to be able to move in the correct direction, but they must do so by changing an xoffset and yoffset variable instead of saying

move [x] steps
What would be the math that converts direction into an x and y change?

Last edited by Billybob-Mario (2012-07-18 19:14:19)

Offline

 

#2 2012-07-18 19:01:34

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: [Math] How to move in a direction without taking steps?

forever
change x by ([sin v] of (angle))
change y by ([cos v] of (angle))
end


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#3 2012-07-18 19:05:59

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: [Math] How to move in a direction without taking steps?

MathWizz wrote:

forever
change x by ([sin v] of ((angle)*[x]))
change y by ([cos v] of ((angle) * [x]))
end

Move x steps translates into this.

So if you want to move 10 steps replace x with 10.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#4 2012-07-18 19:09:51

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: [Math] How to move in a direction without taking steps?

Wes64 wrote:

MathWizz wrote:

forever
change x by ([sin v] of ((angle)*[x]))
change y by ([cos v] of ((angle) * [x]))
end

Move x steps translates into this.

So if you want to move 10 steps replace x with 10.

Oh, derp. You still got it wrong though.

forever
change x by (([sin v] of (angle))*(x))
change y by (([cos v] of (angle))*(x))
end

Last edited by MathWizz (2012-07-18 19:11:19)


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#5 2012-07-18 19:12:16

Billybob-Mario
Scratcher
Registered: 2008-01-05
Posts: 500+

Re: [Math] How to move in a direction without taking steps?

MathWizz wrote:

forever
change x by ([sin v] of (angle))
change y by ([cos v] of (angle))
end

Thank you! It works!

Offline

 

#6 2012-07-18 21:42:06

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: [Math] How to move in a direction without taking steps?

Why can't you use the move block? And if it's because you don't want the direction to change, how about locking the rotation style? http://wiki.scratch.mit.edu/wiki/Rotation_Style Just a thought.  smile

Last edited by Hardmath123 (2012-07-18 21:42:20)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

Board footer