I’m trying to figure out how to smoothly make a balloon randomly float around the map, I’ve looked and looked online for a video or some sort of information that what help me do what I’m trying to do but didn’t fine anything but how to move a part. What I have is a model and I want it to just float around and every so often just change direction, but I need to be smooth, I’ve tried using MoveTo and it just jumps around to different spots of the map. Thx
I suggest using Tween service, on a loop. When the Tween completes the loop repeats and create a new Tween.
The tween should be changing the CFrame value of the primary part of your model.
To feed the CFrame coordinates, choose random numbers inside a “limit box”
Could you give an example of what you mean, please. I think I understand what you’re saying I just don’t know what something like that would look like. Thx
Sure, this is a basic example, you could customize it as you wish.
The balloon is a model, a rig. It contains an invisible Root part, and the Balloon mesh, which is welded to the Root by a motor6d in order to be animated.
The animation is just a “floating” animation, to make the ballon move up and down to make it look like its “floating”, the animation is looped.
The idea would be, each loop iteration, find new random coordinates inside the limitBox, to feed a Goal for the Tween.
The playing time for the tween should be based on the distance the balloon gonna travel, to keep a constant speed, Im using 6 studs per second.
The limitBox is just an giant invisible part anchored in Workspace to make easier to control the waypoints the balloon is allowed to travel, all waypoints are coordinates inside the limitBox
After playing the tween, the loop will wait until the tween is completed in order to continue with the next iteration. Theres a final wait(1), it can be removed if you dont want the balloon to wait at the goal position.
Mainly you should play with the script, the variables, build your “floating animation” to make it look more realistic, and build your rig model balloon so you can animate it.
local TS = game:GetService("TweenService")
local balloon = script.Parent.PrimaryPart -- The ballon rig model
local LimitBox = game.Workspace:WaitForChild("LimitBox") -- the limitbox
-- How fast the balloon will travel to its goal
local studPerSec = 6
-- Loading and playing the animation of floating
local FloatAnim = script.Parent:WaitForChild("FloatAnim")
local AnimController = script.Parent:WaitForChild("AnimationController")
local AnimTrack = AnimController:LoadAnimation(FloatAnim)
AnimTrack:Play()
-- the infinite loop updating new coordinates inside the limitbox playing tween
while true do
local newCFrame = LimitBox.CFrame * CFrame.new(math.random(-LimitBox.Size.X/2, LimitBox.Size.X/2),math.random(-LimitBox.Size.Y/2, LimitBox.Size.Y/2),math.random(-LimitBox.Size.Z/2, LimitBox.Size.Z/2))
local distance = (balloon.Position-newCFrame.Position).Magnitude
local Info = TweenInfo.new(distance/studPerSec, Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
warn("distance to travel:", distance)
warn("time to reach goal:", distance/studPerSec)
local BalloonTween = TS:Create(balloon, Info, {CFrame = newCFrame})
BalloonTween:Play()
BalloonTween.Completed:Wait()
-- wait time before start anim again, could be 0
wait(1)
end
Its a very basic “floating animation” but, does the trick
Awesome thank you so much for all you help!!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.