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:


liam48D
Scratcher
1000+ posts

Strafing

Probably like this:
definestrafeleftn without screen-refreshturn90degreesmovenstepsturn90degreesdefinestraferightn without screen-refreshturn90degreesmovenstepsturn90degrees
Or you could do this for more control:
definestrafenstepsdirectiondturnddegreesmovenstepsturnddegrees
Hope I helped!
nathanprocks
Scratcher
1000+ posts

Strafing

Trigonometry is the best way as it doesn't require rotating the sprite before moving it.
definemovenstepsindirectiondgotox:xposition+sinofd*ny:yposition+cosofd*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.
ProdigyZeta7
Scratcher
1000+ posts

Strafing

definestrafelefttstepschangexbyt*sinofdirection-90//Thinkofitaspointing-90andmovingforwardchangeybyt*cosofdirection-90definestraferighttstepschangexbyt*sinofdirection+90//Thinkofitaspointing90andmovingforwardchangeybyt*cosofdirection+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

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

Strafing

nathanprocks wrote:

Trigonometry is the best way as it doesn't require rotating the sprite before moving it.
definemovenstepsindirectiondgotox:xposition+sinofd*ny:yposition+cosofd*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
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.
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

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
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.
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
pixelmeap
New Scratcher
1 post

Strafing

What if I am using… (The trigonometry)
pointtowardsmouse-pointer
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).
_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?
NickyNouse
Scratcher
1000+ posts

Strafing

pixelmeap wrote:

What if I am using… (The trigonometry)
pointtowardsmouse-pointer
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.
definemovenstepsindirectiondgotox:xposition+sinofd*ny:yposition+cosofd*n
To move sideways to the sprite, you would use the block like this:
move20stepsindirectiondirection-90

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

Powered by DjangoBB