Mouse.hit to become a sphere

You can write your topic however you want, but you need to answer these questions:

  1. I want to make it so that the Mouse.hit vector has a radius so that it collides with objects in all directions. In the screenshot, my current selector sphere is partially engulfed by the baseplate. How do I make it so that it does collide. It’s probably a parameter or well-known setting that I’ve just not heard of.

  2. I’ve tried to search for similar queries on the website by found nothing relevant

local selector = RS.selector
local player = game:GetService("Players").LocalPlayer

script.Parent.Equipped:Connect(function()
	player:GetMouse().TargetFilter = selector
	selector.Parent = workspace
	while script.Parent.Equipped do
		selector.Position = player:GetMouse().Hit.Position
		wait(.05)
	end
end)

sphereIssue

2 Likes

Try this

local selector = RS.selector
local player = game:GetService("Players").LocalPlayer

script.Parent.Equipped:Connect(function()
	player:GetMouse().TargetFilter = selector
	selector.Parent = workspace
	while script.Parent.Equipped do
		selector.Position = player:GetMouse().Hit.Position + Vector3.new(0,selector.Size.Y/2,0)
		task.wait(.05)
	end
end)
2 Likes

sort of. I meant that it should collide in all directions and the baseplate was an example. The other problem is that the mouse isn’t centred inside of the sphere it sort of sits at the bottom because the position of the mouse is unaltered. I’ve edited the post to be more accurate.

2 Likes

Trying using Sphere casting:

local Params = RaycastParams.new() --Please configure to ignore the sphere

Params.FilterType = Enum.RaycastFilterType.Exclude

local Player = **The player**
local Sphere = **The sphere**

Params.FilterDescendantsInstances = {Sphere}

local SphereSize = 3 --Size of the sphere

local Origin = workspace.CurrentCamera.CFrame.Position --The players camera position

local Direction = (Vector3.new(Player:GetMouse().Hit.Position) - Origin) --The mouses position, trying reversing if its inverted, brain not worky

local Spherecast = workspace:Spherecast(Origin, SphereSize, Direction, Params)

local SpherePosition = Spherecast and (Origin + Direction.Unit*Spherecast.Distance) or (Origin + Direction) --The final sphere position

Sphere.Position = SpherePosition
4 Likes

it kind of works, but it seems to be oddly dependant on the camera as opposed to the mouse. Although I have played around with some of the parameters and expressions to try and get it to work, the result is very similar to this:


the sphere is positioning itself onto the object in front of the camera regardless of the mouse’s position

1 Like

I dont fully understand what you want but maybe you could do is position it based of the character

2 Likes

what currently happens:


what I’d like to happen:

(something a bit like studio’s built-in collision detector so that you can’t put the sphere inside an object)
sorry I didn’t realise how unclear I was. I hope this helps.

I don’t think I can code that as there’d be no way to know where the object the sphere is colliding with, but I’m a beginner scripter so I don’t know for sure.

1 Like

Not sure if this is possible but could you check if the sphere is coliding with another part and if so find the nearest place to the mouse that its not colliding with somthing

2 Likes

Raycasting | Documentation - Roblox Creator Hub maybe that(im also new to scripting)

2 Likes

Nor am I :sweat_smile:. I thought I saw a similar feature in bloxburg or another building related game, but I’m unsure.
I could do that, but without shortcuts (which I know none of) it would be an intense iterative process.

2 Likes

local Connection = Area.Touched:Connect(function() end)
local TouchingParts = Area:GetTouchingParts()
Connection:Disconnect()

Could that help

2 Likes

possibly. If I could get the direction vectors between a touching part, then move the sphere according to them it might work. I’ll give it a go

1 Like

Ok good luck i dont have acsess to my pc rn

You could possibly get the parts toutching it like you would to make a kill brick but instead of checking for a player you check for a part

1 Like

spherecasting is the way to go. you would have to ignore the player and other camera obstructions.

if you don’t want to ignore any parts, then you would have to do something like what a physics solver does. it finds the nearest positions a sphere(or other shape) could be in without intersecting anything.

i’m not incredibly knowledgeable in that in-depth of physics, and i think anything more than two spheres(or a sphere and a plane) would be a challenge

theres also a hacky solution where you start the spherecast closer to the mouse’s hit position, so that nothing closer gets in the way, but keep in mind that anything intersecting a spherecast’s origin is automatically ignored(and you can’t disable that)

2 Likes

I think I understand, I’ll spherecast from the camera to the mouse.hit and where it stops is the position of my red sphere (I think). I was about to do something similar with regular raycasting, but this seems far easier. I’ll give it a try

1 Like

make sure to get the final position of the sphere instead of the impact point of the ray, here’s what i mean
image
so for the spherecast result = workspace:SphereCast(origin,direction),
the actual position of the sphere is origin + direction.Unit*result.Distance

3 Likes

Thanks, I was just about to do what you said not to, but add the raycastResult.PositionSphereSize-1 and it was an OK solution (didn’t work for some corners), but this works amazingly! I live in Britain, so it has just turned midnight. You have saved me 3 hours sleep :pray:

2 Likes

Not 100% sure why, but I think yours didn’t work because local Direction should be “player:GetMouse().Hit.LookVector”

also, I don’t think spherecast or origin+direction in your penultimate line makes sense.

Thanks for your reply though

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