Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Strafing
- 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:

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:

- liam48D
-
Scratcher
1000+ posts
Strafing
Probably like this:

define strafe left (n) // without screen-refreshOr you could do this for more control:
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
define strafe (n) steps direction (d)Hope I helped!
turn cw (d) degrees
move (n) steps
turn ccw (d) degrees

- 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)))
- 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.

Then again, this is the advanced topics.

- 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.
- FalconGunner99
-
Scratcher
1000+ posts
Strafing
That's a bit more advanced though and may confuse Scratchers who don't know how to use trigonometry.Ah but there is a reason I posted here, that trig was exactly what I'm looking for
Then again, this is the advanced topics.

- FalconGunner99
-
Scratcher
1000+ posts
Strafing
Trigonometry is the best way as it doesn't require rotating the sprite before moving it.Perfect! Thanks for the math help.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)))
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
- NickyNouse
-
Scratcher
1000+ 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.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
I'll bet. Pen is finicky at best.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
- davidnallen11
-
Scratcher
27 posts
Strafing
Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
- davidnallen11
-
Scratcher
27 posts
Strafing
Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
I mean the Trigonometry one
- BookOwl
-
Scratcher
1000+ posts
Strafing
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.
- davidnallen11
-
Scratcher
27 posts
Strafing
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
- pixelmeap
-
New Scratcher
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.)
- _nix
-
Scratcher
1000+ posts
Strafing
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?

- NickyNouse
-
Scratcher
1000+ posts
Strafing
What if I am using… (The trigonometry)Nathanp's code should work no matter what direction the sprite is facing: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.)
Trigonometry is the best way as it doesn't require rotating the sprite before moving it.To move sideways to the sprite, you would use the block like this: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)))
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 Scratcher
1 post
Strafing
hate to be a necromancer,but
its not working for me. the sprite just goes towards the corners
its not working for me. the sprite just goes towards the corners
- 5632622roblox
-
Scratcher
100+ 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.
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))
- Discussion Forums
- » Advanced Topics
-
» Strafing

