Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How can I make a sprite rotate while still moving towards another sprite?
- tritoon
-
Scratcher
40 posts
How can I make a sprite rotate while still moving towards another sprite?
I have some clones spawning at random coordinates. I made them follow the player, but I also would like them to be spinning in circles at all times while still moving towards that player's direction without the use of costumes. Is that possible?
when I start as a clone
point towards [Player]
repeat until <<not <touching [ Player] ?>>
move (10) steps
end
delete this clone
Last edited by tritoon (June 3, 2022 07:03:07)
- RT_Borg
-
Scratcher
1000+ posts
How can I make a sprite rotate while still moving towards another sprite?
Hi tritoon,
I answered a similar question a couple weeks ago, from someone who wanted to follow the mouse, but it's essentially the same to follow a sprite–just change what you're pointing at.
I'll show the details, but you can just transfer the custom block (in the demo at the end) to your own project using backpack (and modify it to point toward a sprite instead of the mouse.)
You can make a custom block (or borrow the one I wrote for a demo). Make sure you check the box “Run without refresh” on the page where you name the block. And a variable that only the custom block uses:
Once you have this, you'll be be able to use it anywhere to move “steps” toward the mouse pointer, even with a spinning sprite. For example:
You can see it working here:
Demo: Move Toward while Rotating
https://scratch.mit.edu/projects/694568663
I hope this helps. Happy to answer any questions.
– RT_Borg
I answered a similar question a couple weeks ago, from someone who wanted to follow the mouse, but it's essentially the same to follow a sprite–just change what you're pointing at.
I'll show the details, but you can just transfer the custom block (in the demo at the end) to your own project using backpack (and modify it to point toward a sprite instead of the mouse.)
You can make a custom block (or borrow the one I wrote for a demo). Make sure you check the box “Run without refresh” on the page where you name the block. And a variable that only the custom block uses:
(last direction) // For this sprite only
define move toward mouse (steps)
set [last direction v] to (direction) // remember which direction the spinning sprite is pointing
point towards [mouse-pointer v] // you could do the same thing toward a sprite instead of the mouse-pointer
move (steps) steps
point in direction (last direction) // reset back to the original direction the sprite was pointing
Once you have this, you'll be be able to use it anywhere to move “steps” toward the mouse pointer, even with a spinning sprite. For example:
when green flag clicked
forever
turn cw (15) degrees
move toward mouse (5)::custom // this is all it takes to move 5 toward the mouse now
end
You can see it working here:
Demo: Move Toward while Rotating
https://scratch.mit.edu/projects/694568663
I hope this helps. Happy to answer any questions.
– RT_Borg
Last edited by RT_Borg (June 3, 2022 07:43:31)
- tritoon
-
Scratcher
40 posts
How can I make a sprite rotate while still moving towards another sprite?
Hi tritoon,That's exactly what I was looking for. Thanks a lot.
I answered a similar question a couple weeks ago, from someone who wanted to follow the mouse, but it's essentially the same to follow a sprite–just change what you're pointing at.
I'll show the details, but you can just transfer the custom block (in the demo at the end) to your own project using backpack (and modify it to point toward a sprite instead of the mouse.)
You can make a custom block (or borrow the one I wrote for a demo). Make sure you check the box “Run without refresh” on the page where you name the block. And a variable that only the custom block uses:(last direction) // For this sprite onlydefine move toward mouse (steps)
set [last direction v] to (direction) // remember which direction the spinning sprite is pointing
point towards [mouse-pointer v] // you could do the same thing toward a sprite instead of the mouse-pointer
move (steps) steps
point in direction (last direction) // reset back to the original direction the sprite was pointing
Once you have this, you'll be be able to use it anywhere to move “steps” toward the mouse pointer, even with a spinning sprite. For example:when green flag clicked
forever
turn cw (15) degrees
move toward mouse (5)::custom // this is all it takes to move 5 toward the mouse now
end
You can see it working here:
Demo: Move Toward while Rotating
https://scratch.mit.edu/projects/694568663
I hope this helps. Happy to answer any questions.
– RT_Borg
- DemonicRager
-
Scratcher
10 posts
How can I make a sprite rotate while still moving towards another sprite?
Hi tritoon,
I answered a similar question a couple weeks ago, from someone who wanted to follow the mouse, but it's essentially the same to follow a sprite–just change what you're pointing at.
I'll show the details, but you can just transfer the custom block (in the demo at the end) to your own project using backpack (and modify it to point toward a sprite instead of the mouse.)
You can make a custom block (or borrow the one I wrote for a demo). Make sure you check the box “Run without refresh” on the page where you name the block. And a variable that only the custom block uses:(last direction) // For this sprite onlydefine move toward mouse (steps)
set [last direction v] to (direction) // remember which direction the spinning sprite is pointing
point towards [mouse-pointer v] // you could do the same thing toward a sprite instead of the mouse-pointer
move (steps) steps
point in direction (last direction) // reset back to the original direction the sprite was pointing
Once you have this, you'll be be able to use it anywhere to move “steps” toward the mouse pointer, even with a spinning sprite. For example:when green flag clicked
forever
turn cw (15) degrees
move toward mouse (5)::custom // this is all it takes to move 5 toward the mouse now
end
You can see it working here:
Demo: Move Toward while Rotating
https://scratch.mit.edu/projects/694568663
I hope this helps. Happy to answer any questions.
– RT_Borg
how do i make it in a straight line?
- Discussion Forums
- » Help with Scripts
-
» How can I make a sprite rotate while still moving towards another sprite?