How do i make something like this with Raycast?

So i want to make something like this:

As you can see in the video, when the mouse goes outside the character still follows while it’s still inside the radius, how can i possibly make an object in Roblox still follow the mouse but it cannot go outside the radius limit?

I’ve successfully made an object follow the mouse, i just need some help on how do i make it still follow the mouse inside the radius limit while the mouse is outside the radius because the object stuck itself in the last position of the mouse when the mouse goes outside the limit

1 Like

I think I know what you mean, but I’m not certain. It would be helpful if you could include images from your project!

If I understand correctly: Assuming you already have the direction (targetPos - startPos) if you then make it normalized (.Unit) you can multiply it by an integer to set its size. You may also get the length of it by doing .Magnitude.

For example:

local direction = targetPos - startPos
local length = math.min(direction.Magnitude, maxLength) -- Will never be longer than your radius
direction = direction.Unit * length -- Resize it
1 Like

Oh okay

Ye, did that already

Didn’t know that you can get the length by using Magnitude tho, guess i learn something new today.

2 Likes

.Unit normalizes the vector (causes it to have a length of 1), and 1 * length will give the vector a length of length. .Magnitude gets the length of a vector. So, this gives us v.Unit * v.Magnitude = v

2 Likes

Ohh okay
Oh also i’m using Raycast for the thing to work in the last video i just sent

Just a side note.


I know this has nothing to do with your problem but I cant help but say that this looks sick!
Tell me when this game comes out!


Best of luck!
~Froyo~

I’ve found a way to make it work, but apparently it’s not the best since Roblox is a 3D game. So yeah.

I’m interested to hear what other method you used for this! I personally would probably have done it like this, but instead of a UI circle I would have made a circle beneath the character and give it a highlight.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.