Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How can i make a sprite stay in a circle, but still go to the mouse pointer?
- The134045Obstacle
-
Scratcher
7 posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
Like that theres a circle sprite and another point sprite that goes to the mouse pointer except if its in the space outside of the circle.
- BereketY
-
Scratcher
500+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
I'm somewhat confused on what you mean. Is it like a constraint, where the point goes as far as it can toward the mouse pointer, or it only goes to the mouse pointer if the mouse pointer is within the circle?
- The134045Obstacle
-
Scratcher
7 posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
I'm somewhat confused on what you mean. Is it like a constraint, where the point goes as far as it can toward the mouse pointer, or it only goes to the mouse pointer if the mouse pointer is within the circle?the mouse pointer can stay outside, but the point will stay in the circle.
- supernavo
-
Scratcher
1000+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
forever
go to [circle v]
if <(distance to [mouse pointer v]) > [circumference here]> then
point towards [mouse pointer v]
move [circumference here] steps
else
go to [mouse pointer v]
end
end
- Coder105024
-
Scratcher
75 posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
forever
set x to: ([sqrt v] of (((radius of circle) * (radius of circle)) / ((((mouse y) / (mouse x)) * ((mouse y) / (mouse x))) + (1))))
set y to ([sqrt v] of (((radius of circle) * (radius of circle)) - (x-position)))
end
That should work fine, but it does make the point only go around the edge of the circle, not inside or outside. If you want it to be able to go inside, use the script posted above ^ ^ ^
Note: if you can't see the entire script, copy/paste this into a reply inside of a forever loop script, then click “preview” (the green checkmark):
set x to: ( of (((radius of circle) * (radius of circle)) / ((((mouse y) / (mouse x)) * ((mouse y) / (mouse x))) + (1))))
set y to ( of (((radius of circle) * (radius of circle)) - (x-position)))
Last edited by Coder105024 (Nov. 21, 2022 19:24:58)
- Oumuamua
-
Scratcher
1000+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
A different approach:


- Oumuamua
-
Scratcher
1000+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
An off center costume can do it pretty well too


Last edited by Oumuamua (Nov. 21, 2022 19:49:25)
- T_S_H_M
-
Scratcher
11 posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
when green flag clicked
forever
go to [mouse pointer]
if <touching [circle] ?> then
change x by (-something)
or
change y by (-something)
end
end
- TheWeeklyReader
-
Scratcher
100+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
You might be able to make it so the background of the circle is a different sprite ghost 99, and if the mouse is touching that, then it goes to the mouse, but if it is outside of the 99 ghost sprite, it somehow does something like
...:://in ball that goes to mouse
repeat until <(mouse touching?) = [yes]>
go to [sensing 99 ghost sprite v]
point towards [mouse pointer v]
move (radius of sensing circle) steps
end
when green flag clicked:://in new sprite that forever goes to the mouse
forever
if <touching [mouse pointer v]>
set [mouse touching? v] to [yes]
end::control
- Yusei-Fudo
-
Scratcher
1000+ posts
How can i make a sprite stay in a circle, but still go to the mouse pointer?
(#5)That is so long bro :'D
- snip -
- Discussion Forums
- » Help with Scripts
-
» How can i make a sprite stay in a circle, but still go to the mouse pointer?







