Discuss Scratch

FalconGunner99
Scratcher
1000+ posts

Strafing

I asked this in /helpwithscripts/ but everyone got really confused for some reason.

Is there a way to make a sprite strafe?

As in move sideways relative to the sprite, rather than x and y.

Just in case, here's an example:

I want the sprite to be pointing this way:


And moving this way:




; Oh this? This is just my semicolon. I got it a long time ago, it's quite innocuous. Don't worry about it.

















You —> http://i.imgur.com/iVHfwLc.gifv




















liam48D
Scratcher
1000+ posts

Strafing

Probably like this:
define strafe left (n) // without screen-refresh
turn ccw (90) degrees
move (n) steps
turn cw (90) degrees
define strafe right (n) // without screen-refresh
turn cw (90) degrees
move (n) steps
turn ccw (90) degrees
Or you could do this for more control:
define strafe (n) steps direction (d)
turn cw (d) degrees
move (n) steps
turn ccw (d) degrees
Hope I helped!

202e-202e-202e-202e-202e UNI-CODE~~~~~
nathanprocks
Scratcher
1000+ posts

Strafing

Trigonometry is the best way as it doesn't require rotating the sprite before moving it.
define move (n) steps in direction (d)
go to x: ((x position) + (([sin v] of (d)) * (n))) y: ((y position) + (([cos v] of (d)) * (n)))


My browser / operating system: Macrosoft Winding XO, Internet Exploder 6.0, Angel Player ver.:1.2.5
;
liam48D
Scratcher
1000+ posts

Strafing

That's a bit more advanced though and may confuse Scratchers who don't know how to use trigonometry.

Then again, this is the advanced topics.

202e-202e-202e-202e-202e UNI-CODE~~~~~
ProdigyZeta7
Scratcher
1000+ posts

Strafing

define strafe left (t) steps
change x by ((t) * ([sin v] of ((direction) - (90))) // Think of it as pointing -90 and moving forward
change y by ((t) * ([cos v] of ((direction) - (90)))
define strafe right (t) steps
change x by ((t) * ([sin v] of ((direction) + (90))) // Think of it as pointing 90 and moving forward
change y by ((t) * ([cos v] of ((direction) + (90)))



MathWizz
Scratcher
100+ posts

Strafing

Note that changing x and y individually will make any pen marks in a jagged fashion. It probably won't be an issue in most cases but is something to keep in mind if you plan on using the pen.

running Chromium 42.0.2311.90 with Flash Player 15.0.0.189 on Arch Linux 3.19.5-1-ck
MathWizzJsScratch && sb.js & Amber (coming soon! maybe)
FalconGunner99
Scratcher
1000+ posts

Strafing

liam48D wrote:

That's a bit more advanced though and may confuse Scratchers who don't know how to use trigonometry.

Then again, this is the advanced topics.
Ah but there is a reason I posted here, that trig was exactly what I'm looking for


; Oh this? This is just my semicolon. I got it a long time ago, it's quite innocuous. Don't worry about it.

















You —> http://i.imgur.com/iVHfwLc.gifv




















FalconGunner99
Scratcher
1000+ posts

Strafing

nathanprocks wrote:

Trigonometry is the best way as it doesn't require rotating the sprite before moving it.
define move (n) steps in direction (d)
go to x: ((x position) + (([sin v] of (d)) * (n))) y: ((y position) + (([cos v] of (d)) * (n)))
Perfect! Thanks for the math help.

MathWizz wrote:

Note that changing x and y individually will make any pen marks in a jagged fashion. It probably won't be an issue in most cases but is something to keep in mind if you plan on using the pen.
Yup, I figured, but pen isn't an issue for the project I'm using


; Oh this? This is just my semicolon. I got it a long time ago, it's quite innocuous. Don't worry about it.

















You —> http://i.imgur.com/iVHfwLc.gifv




















NickyNouse
Scratcher
1000+ posts

Strafing

MathWizz wrote:

Note that changing x and y individually will make any pen marks in a jagged fashion. It probably won't be an issue in most cases but is something to keep in mind if you plan on using the pen.
I know this is resolved but I just wanna say, setting x and y individually on pen projects has caused me so much stress you don't even know
FalconGunner99
Scratcher
1000+ posts

Strafing

NickyNouse wrote:

MathWizz wrote:

Note that changing x and y individually will make any pen marks in a jagged fashion. It probably won't be an issue in most cases but is something to keep in mind if you plan on using the pen.
I know this is resolved but I just wanna say, setting x and y individually on pen projects has caused me so much stress you don't even know
I'll bet. Pen is finicky at best.


; Oh this? This is just my semicolon. I got it a long time ago, it's quite innocuous. Don't worry about it.

















You —> http://i.imgur.com/iVHfwLc.gifv




















davidnallen11
Scratcher
27 posts

Strafing

Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?

Take everything,give nothing back.
davidnallen11
Scratcher
27 posts

Strafing

davidnallen11 wrote:

Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?

I mean the Trigonometry one

Take everything,give nothing back.
BookOwl
Scratcher
1000+ posts

Strafing

davidnallen11 wrote:

Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
Please don't necropost. I assume that you could just change the input to the block.

who needs signatures
davidnallen11
Scratcher
27 posts

Strafing

BookOwl wrote:

davidnallen11 wrote:

Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
Please don't necropost. I assume that you could just change the input to the block.

Actually I have no idea about the more blocks section.I always avoided it when possible

Take everything,give nothing back.
pixelmeap
New to Scratch
1 post

Strafing

What if I am using… (The trigonometry)
point towards [mouse-pointer v]
Either I am very dumb or it doesn't work like that, also, do you put it on the button you use to usually turn? (Like if I were using WASD and A was turn 90 degrees.)
hiccup01
Scratcher
100+ posts

Strafing

Please don't necropost (post on an old topic).

I'm a veteran Scratcher who likes to challenge themself with Scratch's limited toolset.
website | github
_nix
Scratcher
1000+ posts

Strafing

hiccup01 wrote:

Please don't necropost (post on an old topic).
Asking a question related to an old topic is fine.

Maybe learn about what “necroposting” is okay before requesting someone doesn't necropost at all?

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
NickyNouse
Scratcher
1000+ posts

Strafing

pixelmeap wrote:

What if I am using… (The trigonometry)
point towards [mouse-pointer v]
Either I am very dumb or it doesn't work like that, also, do you put it on the button you use to usually turn? (Like if I were using WASD and A was turn 90 degrees.)
Nathanp's code should work no matter what direction the sprite is facing:

nathanprocks wrote:

Trigonometry is the best way as it doesn't require rotating the sprite before moving it.
define move (n) steps in direction (d)
go to x: ((x position) + (([sin v] of (d)) * (n))) y: ((y position) + (([cos v] of (d)) * (n)))
To move sideways to the sprite, you would use the block like this:
move (20) steps in direction ((direction) - (90)) :: custom

And yeah, you would put it on the button you use to turn.

Last edited by NickyNouse (Dec. 16, 2016 20:07:06)

Falloutcollab
New to Scratch
1 post

Strafing

hate to be a necromancer,but
its not working for me. the sprite just goes towards the corners
5632622roblox
Scratcher
100+ posts

Strafing

liam48D wrote:

That's a bit more advanced though and may confuse Scratchers who don't know how to use trigonometry.

Then again, this is the advanced topics.

tbh yeah

but like im in 9th grade and i get it perfectly and dont even know what trigonometry is

in fact ive applied this quite a few times in stuff like raycasters (i made a maze-like one in smilebasic and i also made one in computercraft (minecraft))

My browser / operating system: Cheese 10 (sometimes Cheesuntu), Googleese Chreese 62.0.3202.94 (Co-Jack Flavor) (64 bite-sized cubes), Flash 27.0 (recheese 0)
i like making frankenstein css (using stylish to paste css from one website to another) and results are either good or bad FLASHLIGHT IS FEMALE!!!!!

Powered by DjangoBB