Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a sprite rotate around another using your mouse.
- Terragamza720
-
Scratcher
12 posts
How to make a sprite rotate around another using your mouse.
Im making a game wear you swing your sword/ pickaxe around and as you move your mouse the tools will rotate around the player but I don't know how to code that.
- Thingied
-
Scratcher
1000+ posts
How to make a sprite rotate around another using your mouse.
when gf clicked
set [offset v] to (0)
forever
go to [player v]
point towards [mouse-pointer v]
turn cw (offset) degrees
if <([abs v] of(offset))>(0)> then
change [offset v] by ((multiplier::grey)*(()-((offset)/([abs v] of (offset))
end
when gf clicked
forever
if <mouse down?>then
repeat (...::grey)
change [offset v] by (...::grey)
end
wait until <not<mouse down?>>
- Terragamza720
-
Scratcher
12 posts
How to make a sprite rotate around another using your mouse.
when gf clicked
set [offset v] to (0)
forever
go to [player v]
point towards [mouse-pointer v]
turn cw (offset) degrees
if <([abs v] of(offset))>(0)> then
change [offset v] by ((multiplier::grey)*(()-((offset)/([abs v] of (offset))
end
when gf clicked
forever
if <mouse down?>then
repeat (...::grey)
change [offset v] by (...::grey)
end
wait until <not<mouse down?>>
whats the multiplier and what do I put in the minus section.
Im a noob at coding
- Yusei-Fudo
-
Scratcher
1000+ posts
How to make a sprite rotate around another using your mouse.
whats the multiplier and what do I put in the minus section.
Im a noob at coding
The minus part that's left blank means 0, so you don't have to put anything there.
As for multiplier, I'm not sure, but it's probably the distance to the mouse pointer? IDK
- Thingied
-
Scratcher
1000+ posts
How to make a sprite rotate around another using your mouse.
As for multiplier, I'm not sure, but it's probably the distance to the mouse pointer? IDKBasically it's how fast the tool retracts.
- Terragamza720
-
Scratcher
12 posts
How to make a sprite rotate around another using your mouse.
As for multiplier, I'm not sure, but it's probably the distance to the mouse pointer? IDKBasically it's how fast the tool retracts.
When I do the code it stays inside of the player. I want it to circle around the player when you move your mouse and not on click.
This is what happens when i do the code:
https://scratch.mit.edu/projects/547311077/
- Thingied
-
Scratcher
1000+ posts
How to make a sprite rotate around another using your mouse.
Convert the costume to be vector and move it a little down and to the right like this:

The other script was terrible so here's a better version:


The other script was terrible so here's a better version:

- Terragamza720
-
Scratcher
12 posts
How to make a sprite rotate around another using your mouse.
Convert the costume to be vector and move it a little down and to the right like this:
The other script was terrible so here's a better version:
It works. Thank you.
- HypnoMaker
-
Scratcher
4 posts
How to make a sprite rotate around another using your mouse.
when green flag clicked
if <mouse down?> then
repeat until <not <mouse down?>>
point towards [mouse v]
end
end
end
Last edited by HypnoMaker (Feb. 5, 2025 23:19:06)
- HypnoMaker
-
Scratcher
4 posts
How to make a sprite rotate around another using your mouse.
when green flag clicked
switch costume to
go to
switch costume to
go to
- HypnoMaker
-
Scratcher
4 posts
How to make a sprite rotate around another using your mouse.
when green flag clicked
forever
go to [ mouse-pointer v]
end
[scratchblocks]
when green flag clicked
if <mouse down?> then
repeat until <not <mouse down?>>
point towards [mouse v]
end
end
end
Last edited by HypnoMaker (Feb. 5, 2025 23:19:20)
- Zifowk
-
Scratcher
100+ posts
How to make a sprite rotate around another using your mouse.
you could use a rotation matrix if the player is centered use this link for the rotation matrix the youtube link
- Discussion Forums
- » Help with Scripts
-
» How to make a sprite rotate around another using your mouse.




