Im trying to move an object from position ‘a’ to ‘b’ in x, z cordinates, I want the Y cordinate to remain the same as the original y value (when it reaches the end) , yet while the object is moving have the y value oscillate at the absolute value of sin(x) ( or something where it bounces up and down )
local cycleLength = 3 -- How long each cycle of the oscillation is
local oscillationRange = 3 -- Height of the oscillation
local start = os.clock()
game:GetService("RunService").Hearbeat:Connect(function()
local y = math.abs(math.sin(start / cycleLength)) * oscillationRange
end)
math.sin to get the sin value
math.abs to get the absolute sine value
Use this over the course of the animation or tween.
I just ended up putting it in a for loop with the amount of bounces you want, with a tween that goes up half a bounce distance and then another tween that goes down the multiply by I for the next bounce and such
just realized I forgot to post the code
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 0, 0)
part.Anchored = true
part.Parent = game.Workspace
local finalPoint = Vector3.new(100,0,150)
local goal = {}
local tweenInfoUp = TweenInfo.new( --
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)
local tweenInfoDown = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In
)
-- having two of these should I think handle the velocity it does really matter just adjust to your pleasure
local distance = math.sqrt(finalPoint.X^2 + finalPoint.Z^2) -- a^2 + b^2 = c^2
local amountOfBounces = math.floor(distance/10) -- this is to sort out the use of bigger and smaller bounces only need if its a random point your bouncing between
-- otherwise you can set it to a number you want
local distancePerBounce = finalPoint/amountOfBounces
print(part.Name .. " is travelling " .. distance .. " Studs In " .. amountOfBounces .. " Bounces")
for i = 1, amountOfBounces do
goal.Position = i*distancePerBounce - Vector3.new(distancePerBounce.X/2,-5,distancePerBounce.Z/2)
local tweenUp = TweenService:Create(part, tweenInfoUp, goal)
goal.Position = i*distancePerBounce
local TweenDown = TweenService:Create(part,tweenInfoDown, goal)
tweenUp:Play()
tweenUp.Completed:Wait()
TweenDown:Play()
TweenDown.Completed:Wait()
end