I want to create block entities that break off when you mine a block, and that will fall to the ground in a natural way. Atm, all I got is a raycast vertically down to the ground, however, problems I have with this is
- Blocks fall vertically down, instead of having a more random drop
- When you mine a block with entities on it, those entities don’t fall
What I mean in the first point, is I want the entity to ‘fly off’ from the block, instead of just falling vertically down, giving them random trajectory to the ground.
--// New entity was created
local function NewEntity(entity)
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Whitelist
Params.FilterDescendantsInstances = {Islands}
Params.IgnoreWater = true
local NewRay = workspace:Raycast(
entity.Position,
Vector3.new(0, -123456789, 0),
Params
)
if not NewRay then return end
local TweenToFloor = TweenService:Create(
entity,
TweenInfo.new(
math.sqrt((entity.Position.Y - NewRay.Position.Y) / 16),
Enum.EasingStyle.Linear
),
{Position = NewRay.Position + Vector3.new(0, 0.75, 0)}
)
TweenToFloor:Play()
TweenToFloor.Completed:Wait()
local NewPosition = entity.Position + Vector3.new(0, 0.75, 0)
local BobTween = TweenService:Create(
entity,
TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,
true
),
{Position = NewPosition}
)
BobTween:Play() -- Make entity bob up and down
-- Make entity rotate
coroutine.wrap(function()
while wait() do
entity.Orientation = Vector3.new(0, entity.Orientation.Y + 2, 0)
end
end)()
end