Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Turn _ degrees until pointing to a certain sprite
- RL1123
-
Scratcher
1000+ posts
Turn _ degrees until pointing to a certain sprite
If the title wasn't clear enough, let me provide an image

please help

please help

- MathPuppy314
-
Scratcher
500+ posts
Turn _ degrees until pointing to a certain sprite
If you want to do it the sloppy way, you could use
You could also find a point towards x y block on scratch and use the output value in the loop.
set [storeAngle1 v] to (direction)
point towards [sprite 2 v]
set [storeAngle2 v] to (direction)
point in direction (storeAngle1)
repeat until <([abs v] of ((direction) - (storeAngle2))) < [1]>//buffer value
turn ccw (1) degrees//anything less than double the buffer value
end
You could also find a point towards x y block on scratch and use the output value in the loop.
Last edited by MathPuppy314 (Nov. 30, 2020 01:52:49)
- Just_ng
-
Scratcher
500+ posts
Turn _ degrees until pointing to a certain sprite
If the title wasn't clear enough, let me provide an image
please help
define turn (degrees) degrees until <condition>
repeat until <condition>
turn cw (degrees) degrees
end
turn (1) degrees until <(direction) = (([atan v] of ((([x position v] of [sprite1 v]) - (x position)) / (([y position v] of [sprite1 v]) - (y position)))) + ((180) * <(y position) > ([y position v] of [sprite1 v])>))>
I think this should work
- Just_ng
-
Scratcher
500+ posts
Turn _ degrees until pointing to a certain sprite
define turn (degrees) degrees until <condition>
repeat until <condition>
turn cw (degrees) degrees
end
turn (1) degrees until <(direction) = (([atan v] of ((([x position v] of [sprite1 v]) - (x position)) / (([y position v] of [sprite1 v]) - (y position)))) + ((180) * <(y position) > ([y position v] of [sprite1 v])>))>
I think this should work
Since the block is too long, this is the condition you need to put in
direction = ((atan of (((x position of another sprite) - (x position)) / ((y position of another sprite) - (y position)))) + ( 180 x <(y position) > (y position of another sprite)>)
Last edited by Just_ng (Nov. 30, 2020 02:26:32)
- DerpyHead0
-
Scratcher
1000+ posts
Turn _ degrees until pointing to a certain sprite
that wouldn't work for 2 reasons:define turn (degrees) degrees until <condition>
repeat until <condition>
turn cw (degrees) degrees
end
turn (1) degrees until <(direction) = (([atan v] of ((([x position v] of [sprite1 v]) - (x position)) / (([y position v] of [sprite1 v]) - (y position)))) + ((180) * <(y position) > ([y position v] of [sprite1 v])>))>
I think this should work
1) the 1 degree increments could pass the sprite
2) the block condition means it only checks it once, it just stays at false after that, just like how setting a variable to (x position) doesn't cause it to change when the player moves
Last edited by DerpyHead0 (Nov. 30, 2020 02:37:33)
- Just_ng
-
Scratcher
500+ posts
Turn _ degrees until pointing to a certain sprite
1. It will go backthat wouldn't work for 2 reasons:define turn (degrees) degrees until <condition>
repeat until <condition>
turn cw (degrees) degrees
end
turn (1) degrees until <(direction) = (([atan v] of ((([x position v] of [sprite1 v]) - (x position)) / (([y position v] of [sprite1 v]) - (y position)))) + ((180) * <(y position) > ([y position v] of [sprite1 v])>))>
I think this should work
1) the 1 degree increments could pass the sprite
2) the block condition means it only checks it once, it just stays at false after that, just like how setting a variable to (x position) doesn't cause it to change when the player moves
2. here it is :
define turn (degrees) degrees until pointing to another sprite
repeat until <(direction) = (([atan v] of ((([x position v] of [sprite1 v]) - (x position)) / (([y position v] of [sprite1 v]) - (y position)))) + ((180) * <(y position) > ([y position v] of [sprite1 v])>))>
turn cw (degrees) degrees
end
turn (1) degrees until pointing to another sprite
Last edited by Just_ng (Nov. 30, 2020 03:10:33)
- animations_enjoy
-
Scratcher
10 posts
Turn _ degrees until pointing to a certain sprite
the easiest method is here see the example:
the forever loop is not compulsory it is just for this example where it points to the sprite forever
when green flag clicked
forever
point towards [your sprite you wanna point towards name]
end
the forever loop is not compulsory it is just for this example where it points to the sprite forever
- Ankit_Anmol
-
Scratcher
500+ posts
Turn _ degrees until pointing to a certain sprite
the easiest method is here see the example:u didn't understand….when green flag clicked
forever
point towards [your sprite you wanna point towards name]
end
the forever loop is not compulsory it is just for this example where it points to the sprite forever
- deck26
-
Scratcher
1000+ posts
Turn _ degrees until pointing to a certain sprite
https://scratch.mit.edu/projects/55006278/ might help. It turns the most efficient direction - clockwise or anti-clockwise. You should be able to spot the block that detects when it is within a certain range and, if you want, you can disable the move after that.
- Discussion Forums
- » Help with Scripts
-
» Turn _ degrees until pointing to a certain sprite