I want to make it so the highlited part´s hitbox doesnt intersext, this is the script im using.
local Player = game.Players.LocalPlayer
Buildmode = Player:GetAttribute("Buildmode")
local Mouse = Player:GetMouse()
while true do
Buildmode = Player:GetAttribute("Buildmode")
if Buildmode == true then
block = game.ReplicatedStorage.SelectBox:Clone()
block.Parent = workspace.Ignore
Mouse.TargetFilter = workspace.Ignore
else
end
while Buildmode == true do
block.Position = Vector3.new(math.round(Mouse.Hit.Position.X) ,math.round(Mouse.Hit.Position.Y) + block.Size.Y / 2 ,math.round(Mouse.Hit.Position.Z) )
wait(0.1)
I suggest you do a raytrace in the direction of the proposed change to the position before you do the setting.
Use the raytrace to determine if the new position would be intersecting the block with another object.
This would be where the distance between the block current position and the hit position is less than the size of the block.
If intersection is determined do not do the setting of the block position.
Yes, but then i have issues with that, lets say i make a ray from where the part appears to the center of the other part, how would i find out the nearest position that does not intersect with the object, if the ray’s origin already intersects?
if the raycast returns a hit use the hit.Position and your block.Position and find the distance between them.
If that distance is less than half the size of your part there will be in intersection.
Ok, then should i move it in the ray’s direction backwards? if so how could I get its direction and how could i invert it.
Edit:I realise that i dont have to invert it because i can just swap the origin and direction. So then I just round the value to the nearest unit and that should be it.
But how can i move the part just a single unit in the ray’s direction?
When I get home i am going to try moving the part by half of the ray’s magnitude