Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Detect a change of direction.
- Proyecto13
- New to Scratch
3 posts
Detect a change of direction.
Hello to everyone,
I have a problem with the approach of this script. I need that script detect when my character change of direction, for example, he was running to direction 90 and suddenly he changes to -90.
My objective with this is make an animation.
Thank you for reading.
I have a problem with the approach of this script. I need that script detect when my character change of direction, for example, he was running to direction 90 and suddenly he changes to -90.
My objective with this is make an animation.
Thank you for reading.
- mstone326
- Scratcher
1000+ posts
Detect a change of direction.
Not sure what you are trying to do in your project but, as a guess, maybe you could create a variable called character_direction and set it to direction. Without seeing the project I can only guess what you are looking for.
set [character_direction v] to (direction)
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- Charles12310
- Scratcher
1000+ posts
Detect a change of direction.
set [previous direction v] to (direction)
wait until <not <(previous direction) = (direction)>>
set [direction change v] to ((direction) - (previous direction))
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- Locomule
- Scratcher
1000+ posts
Detect a change of direction.
if <key [right arrow] pressed?> then
point in direction (90)
do whatever here
else
if <key [left arrow] pressed?> then
point in direction (-90)
do whatever else here
end
end
- Proyecto13
- New to Scratch
3 posts
Detect a change of direction.
Hello, the scripts you gave me don't work. For the people that doesn't understand what i want to do, my objective is that the script detect when the main character suddenly change of direction and in this moment the character make an animation.
And, if you want to make me a recommendation you are welcome.
Here is the link: https://scratch.mit.edu/projects/188453005/. Please understand that the proyect is unfinished.
And, if you want to make me a recommendation you are welcome.
Here is the link: https://scratch.mit.edu/projects/188453005/. Please understand that the proyect is unfinished.
- Locomule
- Scratcher
1000+ posts
Detect a change of direction.
make a variable called New Direction and start it set to 0
make another variable called Last Direction and start it set to whatever direction the player is facing
in move left and move right scripts, check to see if the current direction equals Last Direction
if so, if New Direction equals 0 set it to 1
if not, set Last Direction to the player's current direction and set New Direction to 0
in you animation script, check New Direction's value…
if 0, perform special animation - when done, set New Direction to 1
if 1, perform normal animation
make another variable called Last Direction and start it set to whatever direction the player is facing
in move left and move right scripts, check to see if the current direction equals Last Direction
if so, if New Direction equals 0 set it to 1
if not, set Last Direction to the player's current direction and set New Direction to 0
in you animation script, check New Direction's value…
if 0, perform special animation - when done, set New Direction to 1
if 1, perform normal animation
Last edited by Locomule (Nov. 23, 2017 23:31:49)
- Proyecto13
- New to Scratch
3 posts
Detect a change of direction.
Thanks for your help I make a remix of your recommendations and the definitive script is this (for anyone who has the same question):
when green flag clicked
set [Right direction] to [90]
set [Left direction] to [-90]
forever
if <(Right direction) = (direction)> then
wait until <not <(Right direction) = (direction)>>
set [New direction] to [1]
wait (put the time you want) secs
set [New direction] to [0]
end
if <(Left direction) = (direction)> then
wait until <not <(Left direction) = (direction)>>
set [New direction] to [1]
wait (put the time you want) secs
set [New direction] to [0]
end
Last edited by Proyecto13 (Nov. 24, 2017 18:25:11)
- Locomule
- Scratcher
1000+ posts
Detect a change of direction.
Glad it worked for you, thanks for sharing the script blocks!
- Discussion Forums
- » Help with Scripts
- » Detect a change of direction.