You can write your topic however you want, but you need to answer these questions:
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.
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)
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)
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.
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
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:
(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.
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
Nor am I . 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.
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)
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
make sure to get the final position of the sphere instead of the impact point of the ray, here’s what i mean
so for the spherecast result = workspace:SphereCast(origin,direction),
the actual position of the sphere is origin + direction.Unit*result.Distance
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