I am trying to figure out a way to place a hitbox where my mouse would be placed. I already got the part of the script where if the magnitude between the HumanoidRootPart and Mouse positions meet lower than the area, then it will place the hitbox. I also want a way to get the hitbox to get as close as possible towards the mouse, but still regarding the restraint. Here is some of my code.
local hitbox = game.ReplicatedStorage.Objects.Galactic.GalacticShowerHitbox:Clone()
hitbox.Parent = workspace
local area = 40
local dist = (pos.Position - hrp.Position).Magnitude
if locked then
hitbox.CFrame = hrp.CFrame
elseif not locked then
if dist <= area then
hitbox.Position = pos.Position
else
local dir = (pos.p - hrp.Position).Unit
hitbox.Position = Vector3.new(40, 40, 40) * dir
end
end
So you mean like you want to put the hitbox on the mouse.position but still obeying the restriction? I canβt understand what you desire to achieve, do you want to make the hitbox on the orientation of the mouse, position of the mouse?
If the case is the Position of the mouse, then you need to make some math though!!
Iβm trying to make it to where if the boundary is met, then it will place the hitbox regardless, but if the mouse if past the boundary, it will still place the hitbox, but it wonβt be exactly on top the mouse position, just around the area I want it to be at. While also being in line between the root part and mouse positions
local hitbox = game.ReplicatedStorage.Objects.Galactic.GalacticShowerHitbox:Clone()
hitbox.Parent = workspace
local area = 40
local dist = (pos.Position - hrp.Position).Magnitude
if locked then
hitbox.CFrame = hrp.CFrame
elseif not locked then
if dist <= area then
hitbox.Position = pos.Position
else
local dir = (pos.p - hrp.Position).Unit
hitbox.Position = Vector3.new(40, 40, 40) + dir -- Vector3.new(40,40,40) (the limit) + dir which is the .Magnitude of 1.
end
end
Have you ever trying to add a β+β instead of a β*β?