-
What do you want to achieve? Keep it simple and clear!
So basically i have an “Flying Miner” Object and it have “Mining Laser” which looks like cylinder, i wanna put inside of it a ore block model and using align position to move it inside of cylinder, but it always flyes away from cylinder and starts flying around it. Here is video link: 2022 10 27 14 28 12 - YouTube
-
What is the issue? Include screenshots / videos if possible!
1st
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tryed changing align position parameters. Main problem i think happens in case of object is moving
Currently i have no scripts implemented for that mechanic, only align position
1 Like
Use lerp to animate the CFrame of the ore inside the mining laser.
--\\ Client Ore Animation
local Miner, OreCluster -- set these variables!
task.spawn(function() -- Ore Animation
local current: Part
local time = 0
local angularvelo = Vector3.new()
game:GetService("RunService").RenderStepped:Connect(function(dt) -- Update flying ore CFrame
if current then
time += dt
if time >= 0.5 then
time = 0
current:Destroy()
current = nil
return
end
current.CFrame =
CFrame.new(OreCluster.Position:Lerp(Miner.Position, time / 0.5)) -- position
* CFrame.fromEulerAngles( -- rotation
math.rad(angularvelo.X * dt),
math.rad(angularvelo.Y * dt),
math.rad(angularvelo.Z * dt)
)
end
end)
while task.wait(1.25) do -- Create flying ore
if not current then
current = OreCluster.Template:Clone() -- flying ore created here (replace with your own code)
angularvelo = Vector3.new(math.random(-60,60),math.random(-60,60),math.random(-60,60))
end
end
end)
If it is still unaligned with the cylinder, maybe your cylinder is positioned incorrectly.
Hey, where i should put this script? And what type of script local or server.
EDIT: Oh wait forgot what Heartbeat works only in local script. So anyways where i should put that
EDIT2: The main problem this script should start working only when player buys that thing, and by default miner is located in serverStorage.TycoonStorage, and after that getting cloned to workspace.
Oh i have an idea, because script should get fired only after player buy that thing, so i will just fire event when parent of miner changed
RenderStepped only works in a LocalScript, so you would put that script in a local script.
Alright so i edited code a bit so it won’t work always, so like that
Script:
local AnimationHandler = workspace.Events.AnimationHandler
local Miner = script.Parent
local Owner = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent:GetAttribute("Owner")
local Player = game:GetService("Players"):FindFirstChild(Owner)
--Miner:GetPropertyChangedSignal("Parent"):Connect(function()
AnimationHandler:FireClient(Player, "FDAnim", Miner)
--end)
Local Script:
local AnimationHandler = workspace.Events.AnimationHandler
local OreCluster = game:GetService("ServerStorage").OreStuff.Ore3
AnimationHandler.OnClientEvent:Connect(function(animation, Miner)
if animation == "FDAnim" then
task.spawn(function() -- Ore Animation
local current: Part
local time = 0
local angularvelo = Vector3.new()
game:GetService("RunService").RenderStepped:Connect(function(dt) -- Update flying ore CFrame
if current then
time += dt
if time >= 0.5 then
time = 0
current:Destroy()
current = nil
return
end
current.CFrame =
CFrame.new(OreCluster.Position:Lerp(Miner.Position, time / 0.5)) -- position
* CFrame.fromEulerAngles( -- rotation
math.rad(angularvelo.X * dt),
math.rad(angularvelo.Y * dt),
math.rad(angularvelo.Z * dt)
)
end
end
end)
while task.wait(1.25) do -- Create flying ore
if not current then
current = OreCluster.Template:Clone() -- flying ore created here (replace with your own code)
angularvelo = Vector3.new(math.random(-60,60),math.random(-60,60),math.random(-60,60))
end
end
end)
end)
Will that work properly?
I think it will work. It would be more efficient to make the script automatically detect that the animation should be playing somewhere, but yours is easier to read. So it’s fine!
Uhh i’m literally dumb, where i should put that ore template and should i put parent of ore clone(current)
The ore template is just the white cube coming out of the ore cluster. It will be cloned and animated every 1.25 seconds, for 0.5 seconds.
Should it be unanchored cuz nothing just happens
EDIT: It is getting fired so it work
It should be anchored since your animating the CFrame of it.
Hmm Well then it does nothing (30 lettersssssss), i mean it not creates a ore i can’t really see it
EDIT: I think i made something wrong with cloning it
Also what about part collision, should be on or off?
I don’t think the collision will matter unless the miner is being animated by physics and attachments. If you use that, then the collision should be off for everything in that animation.
No miner is animated by CFrame and CFrame Angles with using 2 welds between spinning part
Alright. Even though I just said collision shouldn’t matter, I suggest turning collisions off for everything in that model so it doesn’t hit the player in the head, lol.
...
while task.wait(1.25) do -- Create flying ore
if not current then
current = OreCluster:Clone() -- flying ore created here (replace with your own code)
angularvelo = Vector3.new(math.random(-60,60),math.random(-60,60),math.random(-60,60))
end
end
end)
end)
That’s how i hold that, maybe that’s a problem
Well that’s right it pushed me 3 times off until i made a screenshot
There should be a template for that white cube in the mining laser, that would be what you clone and animate.
Oh, I forgor to parent the cloned ore. Parent that to where ever you want the flying white cube to be.