You can write your topic however you want, but you need to answer these questions:
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.
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.
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)
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.
If you want to always keep the cube on the ground, you could do this:
Fire a raycast from the cube’s position down to the ground
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).