Make items drop without falling through the world

I’m trying to make my entites fall down to the ground, but not fall through the map. This is what I got currently

function EntityControl:Create(entityType, amount, position)
	for i = 1, amount do
		local Entity = Instance.new('Part')
		Entity.Color = EntityData[entityType].Color
		Entity.Material = Enum.Material.SmoothPlastic
		Entity.Name = entityType
		Entity.Position = position
		Entity.Anchored = true
		Entity.CanCollide = false
		Entity.Size = Vector3.new(1, 1, 1)
		
		Entity.Parent = Entites
				
		Debris:AddItem(Entity, 5)
		
		local NewPosition = Entity.Position + Vector3.new(0, 0.75, 0)
	 
		local Tween = TweenService:Create(Entity, Info, {Position = NewPosition})
		
		Tween:Play()
		
		spawn(function()
			while wait() do
				Entity.Orientation = Vector3.new(0, Entity.Orientation.Y + 2, 0)
			end
		end)
	end
end

Which does this
robloxapp-20191230-1658494

So they kinda just stay mid air.

I’ve tried setting Anchored to false, CanCollide to true, but they glitch out with the tweening and what not. I thought about maybe just making them spawn on the ground, but if I let them fall naturally they should spread out right? In the gif you can only see 1 item, but there’s actually 3, they are just all grouped together, which I don’t want, I want all 3 to kinda fall to the ground, be a little spread out, and just bob on the ground

1 Like

You can make it so when you destroy the tree, the entity falls, and when it touches the ground, it starts playing the animation(then you would set the anchored to true)

local Entity = Instance.new('Part')
		Entity.Color = EntityData[entityType].Color
		Entity.Material = Enum.Material.SmoothPlastic
		Entity.Name = entityType
		Entity.Position = position
		Entity.Anchored = false
		Entity.CanCollide = true
		Entity.Size = Vector3.new(1, 1, 1)
		
		Entity.Parent = Entites
				
		Debris:AddItem(Entity, 20)
		
		Entity.Touched:Connect(function(hit)
			if hit.Name == 'Baseplate' then
				Entity.Anchored = true
				Entity.CanCollide = false
				
				local NewPosition = Entity.Position + Vector3.new(0, 0.75, 0)
	 
		local Tween = TweenService:Create(Entity, Info, {Position = NewPosition})
		
		Tween:Play()
		
		spawn(function()
			while wait() do
				Entity.Orientation = Vector3.new(0, Entity.Orientation.Y + 2, 0)
			end
		end)
			end
		end)

Tried this, and they kinda fell to the ground, then like a split second got teleported back up again, and started doing the tween

No, what I mean is that you make the can collide to true and the anchored to false, and when it hits the ground, it wont go through because the can collide is true. So, when it touches the ground, you tween it up a bit, and start playing the animation(with the anchored set to true after it touches the ground)

Changing that didn’t do anything different tho :confused:

You could ray cast down and see how far it is until the floor. Then do an animation down to the floor and then a floating animation - that should work.

local RayToGround = Ray.new(Entity.Position, Vector3.new(0, -1 * 100, 0))

		local PartFound, Pos = workspace:FindPartOnRay(RayToGround)
		print(PartFound, Pos)

My raycast seems to get my rays that are created from a hitbox module
RaycastHitboxDebugPart 25.5, 2.21859074, -33 (x3)
(using a module that creates rays on melee items for good hitboxes)

How can I fix this

What is this position? If it is the position of the tree trunk, then you would be able to set the position to:
Vector3.new(0, (position.x - TreeTrunk.Size.x / 2) + 0.5, 0)

I thought about that, but when I implement other items, I dont think having that one forkula would work on all models

Why do you need the part without collisions, is it so that its unable to collide with players and such? The only way I can fathom you fixing this is to use collision groups to filter collisions. That means to create a few groups for different parts of your game and make said blocks not collide with them.

Well another reason I don’t really wanna just set the Anchored to false and let it fall naturally is because when parts hit the floor, they can bounce around, flip onto their sides etc. I want the part to fall down, with a little bit of a curve to each one, so they spread out, and hit the ground facing up

This doesn’t work anyway

Entity.Position = Vector3.new(0, (source.Position.X - source.Size.X / 2) + 0.5, 0)

If ‘source’ is the TreeTrunk. It spawns them in the centre of the map, around like 0,15,0

That’s my bad… Rather than source.Position.X - source.Size.X / 2, it should be source.Position.Y - source.Size.Y / 2

Still doesn’t work. Tried

Entity.Position = Vector3.new(source.Position.X, (source.Position.Y - source.Size.Y / 2) + 0.5, source.Position.X)

Spawns quite a distance away from the tree

I’m actually really sorry, but I must have been really distracted at the time of my post.

Entity.Position = Vector3.new(source.Position.X, (source.Position.Y - source.Size.Y / 2) + 0.5, source.Position.Z)

I had for some reason put the code in as (X, X, X) rather than (X, Y, Z)

That’s literally the exact code I just replied with…

EDIT
Hol up nvm, I see that I used X instead of Z

1 Like

I still have the problem of them all being stuck inside each other tho :confused:

You could add some random displacement on the X and Z axis.

Entity.Position = Vector3.new(
    source.Position.X + math.random(-3, 3),
    (source.Position.Y - source.Size.Y / 2) + 0.5,
    source.Position.Z + math.random(-3, 3)
)

You could change up the (-3, 3) until you get a result of your liking.