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:
; 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-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
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)))
- 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.
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
MathWizz — JsScratch && sb.js & Amber (coming soon! maybe)
- FalconGunner99
- Scratcher
1000+ posts
Strafing
Ah but there is a reason I posted here, that trig was exactly what I'm looking for 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.
; 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
Perfect! Thanks for the math help. 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)))
Yup, I figured, but pen isn't an issue for the project I'm using 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.
; 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
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 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
I'll bet. Pen is finicky at best.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 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.
; 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
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
Please don't necropost. I assume that you could just change the input to the block. Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
who needs signatures
- davidnallen11
- Scratcher
27 posts
Strafing
Please don't necropost. I assume that you could just change the input to the block. Are you able to make a strafing script wit variables?Can you adjust the speed of the strafe?
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.)
- _nix
- Scratcher
1000+ posts
Strafing
Asking a question related to an old topic is fine. Please don't necropost (post on an old topic).
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
Nathanp's code should work no matter what direction the sprite is facing: 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.)
To move sideways to the sprite, you would use the block like this: 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)))
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
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))
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!!!!!
- Discussion Forums
- » Advanced Topics
- » Strafing