You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I’d like to smoothly animate 3 ice-shards coming from underground to just above ground.
- What is the issue? Include screenshots / videos if possible!
The ice shards jitter pretty badly and flash causing a bad animation.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried TweenService but found a tutorial online showing the lerp method (which I’m more familiar). I have turned CanCollide OFF so as not to interfere with the terrain. Here is relavent code:
Client: (simply fires to server)
remotes.IceFiredByPlayer:FireServer()
Server: (spawns the ice)
local function randomSpawnObject(object, minVector, maxVector, offset)
local raycastOrigin = Vector3.new(random:NextNumber(minVector.X, maxVector.X), random:NextNumber(minVector.Y, maxVector.Y), random:NextNumber(minVector.Z, maxVector.Z))
local raycastDirection = -Vector3.yAxis
local distance = 1000
local result = workspace:Raycast(raycastOrigin, raycastDirection * distance)
if result then
object:PivotTo(CFrame.new(result.Position.X, result.Position.Y - offset, result.Position.Z))
end
end
remotes.IceFiredByPlayer.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("HumanoidRootPart")
local originPosition = humanoid.Position
local ice1 = iceShard:Clone()
local ice2 = iceShard:Clone()
local ice3 = iceShard:Clone()
ice1.Parent = workspace
ice2.Parent = workspace
ice3.Parent = workspace
randomSpawnObject(ice1, Vector3.new(originPosition.X - 20, originPosition.Y, originPosition.Z - 20), Vector3.new(originPosition.X + 20, originPosition.Y, originPosition.Z + 20), 0.5)
randomSpawnObject(ice2, Vector3.new(originPosition.X - 20, originPosition.Y, originPosition.Z - 20), Vector3.new(originPosition.X + 20, originPosition.Y, originPosition.Z + 20), 0.5)
randomSpawnObject(ice3, Vector3.new(originPosition.X - 20, originPosition.Y, originPosition.Z - 20), Vector3.new(originPosition.X + 20, originPosition.Y, originPosition.Z + 20), 0.5)
debrisService:AddItem(ice1, 1.1)
debrisService:AddItem(ice2, 1.1)
debrisService:AddItem(ice3, 1.1)
end)
Finally, the animation (lerp) which is on the ice shard itself. The script runs when the ice is cloned into the world.
local runService = game:GetService("RunService")
local iceShard = script.Parent
local startCFrame = iceShard.Union.CFrame
local targetCFrame = iceShard.Union.CFrame * CFrame.new(0, 6, 0)
local lerpTime = 1.1
local startTime = tick()
local runningTime = 0
local lerp
lerp = runService.Heartbeat:Connect(function(deltaTime)
runningTime += deltaTime
local alpha = runningTime / lerpTime
script.Parent.Union.CFrame = startCFrame:Lerp(targetCFrame, alpha)
if alpha >= 1 then
script.Parent.Union.CFrame = targetCFrame
lerp:Disconnect()
end
end)
My game will have quite a few animations like this so I’d really like to figure this one out. Thanks!