How would I make a part bigger without it clipping into the ground?

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

  1. What do you want to achieve?
    I’m currently scripting for an agario style game, where the player controls a cube collecting coins to become bigger.

  2. What is the issue?
    The problem is that when the player picks up a coin, the size increases, but they will start clipping into the ground as they get bigger.

  3. What solutions have you tried so far?
    I’ve tried raising the Y position of the player by a small amount to prevent clipping, but this resulted in an awkward pause after collecting a coin before they could move again, and caused input delay afterwards. I’ve also tried temporarily disabling the weldconstraint to alleviate this issue, but it did not work.

cube.Touched:Connect(function(hitpart)
	if hitpart.Parent == workspace.Coins then		
		hitpart:Destroy()
		cube.Size = Vector3.new(cube.Size.X + 0.5, cube.Size.Y + 0.5, cube.Size.Z + 0.5)
		serverstorage.CoinCollect:Fire(player)
	elseif hitpart.Parent == workspace.Cubes then
		serverstorage.CubeCollision:Fire(player,hitpart)	
	end
end)

Help would be much appreciated. Thanks.

Add Vector.new(0,0.25,0) to the cubes position

I tried this before, but as I said it caused an akward pause and input delay.

try editing the hip height of the humanoid, if there is one

1 Like

What WeldConstraint?

Have you looked to see if you’re getting too many Touched events firing? Touched events are notorious for this.You should also pop open the microprofiler to see what the “awkward pause” actually is.

There’s a weldconstraint keeping the cube in place with the character.

If you want to always keep the cube on the ground, you could do this:

  1. Fire a raycast from the cube’s position down to the ground
  2. Get the position of the raycast and set the cube’s Y position to the raycast position + the cube’s height / 2

Here’s some code that may help:

RunService.RenderStepped:Connect(function()

    local ground_raycast = workspace:Raycast(cube.Position, Vector3.new(0, -math.huge, 0))

    if ground_raycast ~= nil then
        cube.Position = Vector3.new(
            cube.Position.X,
            ground_raycast.Position.Y + cube.Size.Y / 2,
            cube.Position.Z
        )
    end

end)

One thing to note about this is that the raycast may fail if the cube becomes too large too quickly, since the cube’s position would suddenly be inside the ground, so if you were to use this method then you may want to keep this in mind.

So there is a Roblox avatar inside the cube, or what? Normally, when people make this sort of game the character is just the cube, right? (cube is the HumanoidRootPart typically).

increase the Y axis in position so it doesn’t clip

There is a roblox avatar inside the cube, yes.

i mean, if u wouldnt want a part to be clipping into the ground, even tho its big then just set the correct values…

I just tried this, and I ran into the same exact problem. Collecting a coin causes an awkward pause and then input delay.

If you had read the entire post, you would know that isn’t the problem I’m experiencing.