Help with crowding out cube

Hello there! I wanna make crowding out this box:

I tried to use raycast, maybe I’ve done something incorrectly.

A part of the code:

explosionBox.CFrame = CFrame.new(m.Hit.Position)

This is a local script. This function used in while cycle.

1 Like

Can you explain what crowding out is, or link some source explaining it?

1 Like


I wanna make this box crowd out. Like standing on the floor/walls, not inside them

1 Like

Maybe something like this would work?
The change i would make is only getting the direction for one axis at a time

local part = script.Parent

local function move(to : Vector3)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {part}
	
	local current = part.Position
	local direction = to - current
	
	local ray = workspace:Blockcast(part.CFrame, part.Size, direction, params)
	if (ray) then
		part.Position += direction.Unit * ray.Distance
	end
end

move(Vector3.new(-9, 3, 0))

these are the results i got

not moved (red cube is -9, 3, 0)
image

moved
image
image

The reason I suggest doing one direction at a time, in this example i moved it to (-10, 5, 0) and the results aren’t as good
image

1 Like
local function move(to : Vector3)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {part}
	
	local current = part.Position
	
	local directions = {
		Vector3.xAxis * (to.X - current.X),
		Vector3.yAxis * (to.Y - current.Y),
		Vector3.zAxis * (to.Z - current.Z),
	}
	
	for _, direction in next, directions do
		local ray = workspace:Blockcast(part.CFrame, part.Size, direction, params)
		if (ray) then
			part.Position += direction.Unit * ray.Distance
		end
	end
end

move(Vector3.new(-10, 5, 0))

here are the results for doing the directions one at a time going to (-10, 5, 0)
image

1 Like

umm, idk how to correctly use this in my script:

explosionBox = explosionFolder.Box:Clone()
explosionBox.Parent = workspace

explosion_boxFunction = task.spawn(function()
	while wait() do
		if (explosionBox.Position-HRP.Position).Magnitude>200 then
			explosionBox.Color = Color3.fromRGB(74, 36, 24)
			canSpawnExplosion = false
		else
			explosionBox.Color = Color3.fromRGB(186, 91, 60)
			canSpawnExplosion = true
		end

		explosionBox.CFrame = CFrame.new(m.Hit.Position)

		spawnPosition = explosionBox.CFrame.Position
	end
end)
1 Like

ohoh, wait, lemme try smth, i got it

1 Like


1 Like

I did forget to add else to the for loop, so it only moves if the ray hits something. But trying it myself in a mouse position loop it seems to only work in very certain conditions. A different solution i was thinking of is to move it, then block cast all sides and use the normal of the ray to offset it, might work?

1 Like

idk what do I need to say. Just… Try it? idk

1 Like

I’ve been trying for a little bit now but I’m struggling to come up with something. I think you should be going for something like blockcasting and using the ray’s normal. I’ll continue trying tomorrow if you haven’t already solved it by then

1 Like

hey, can you help me?

6yhj5yhjrgthjrtyhdthgr

Do you have CanQuery turned off for the red part? If you have this on that may be the cause to it being so snappy.

not helped(

ehbklekrtghjierhjioerhjkejirthjeiklrthgjiethijethji

nvm, I just made a new method to spawn explosion. Anyways thx guys

1 Like

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