Help on bouncing part forward?

Hello, I am trying to make this part bounce upwards and forwards at the same time. My problem is actually keeping it 1 stud forward, it goes one stud forward midair, then back down it goes again. Here is an example of what it looks like when I try to debug it:

sorry for shitty quality you can probably tell i made this vid on roblox recorder lol

And here is the code to this part:

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	0.5, -- Time
	Enum.EasingStyle.Sine , -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local tween = TweenService:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(0, 5, 1)})

script.Parent.ClickDetector.MouseClick:Connect(function()
	tween:Play()
end)

Can anyone please help me?

{Position = script.Parent.Position + Vector3.new(0, 5, 1)}

Depending on where u want to move the part. Vector3 has 3 values. X, Y Z

In this code your doing the following: Move X by 0 values. Moving the Y value by 5 position values. And moving the Z by 1 position value.

image

[spoiler] you’d be surprised how many forum posts just so happens to have swears in it, trust me.[/spoiler]

Yes, that’s exactly what i want however it’s not staying going for forward in the z-axis, it’s going forward then back where it came back from, which is good for the y-axis, but not for the z-axis.

Oh, here.
image
set that to false

stops midair in the middle of the tween anim, and i think making another animation isn’t very productive.

image

Oh I see, Yeah for that case your gonna have to use 2 tweens. One for Y, One for Z

I tried that but it just plain didn’t work. what should I try now?

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	0.5, -- Time
	Enum.EasingStyle.Sine , -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
local tweenInfo2 = TweenInfo.new(
	0.5, -- Time
	Enum.EasingStyle.Sine , -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local tween = TweenService:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(0, 5, 0)})
local tween2 = TweenService:Create(script.Parent, tweenInfo2, {Position = script.Parent.Position + Vector3.new(0, 0, 1)})

script.Parent.ClickDetector.MouseClick:Connect(function()
	tween:Play()
    tween2:Play()
end)

Did you try this?

I tried something like almost identical to that (variable names were different) and it just slid forward.

Maybe tween only the Y value at the first one, and the Z value at the second one?

did not work. it just went up and stayed there

You can’t do it with tweening so just make a custom tween function like this example:

local TweenService = game:GetService("TweenService")

local stepz = Vector3.new(0, 0, 1)
local stepy1 = Vector3.new(0, 5, 0)
local stepy2 = Vector3.new(0, -5, 0)

function ease(n, dir) -- sine
	if dir == 'Out' then
		return math.sin((n * math.pi) / 2)
	end
	return 1 - math.cos((n * math.pi) / 2);
end
function Tween(posoffset, tweentime, dir)
	local co = coroutine.create(function()
		local start = time()
		local progress = 0
		local prev = ease(progress, dir)
		repeat
			script.Parent.Position += posoffset * (ease(progress, dir) - prev)
			prev = ease(progress, dir)
			task.wait()
			progress = (time() - start) / tweentime 
		until progress >= 1
	end)
	coroutine.resume(co)
end
Tween(stepz, 0.5, 'Out')
Tween(stepy1, 0.5, 'Out')
task.wait(0.5)
Tween(stepy2, 0.5, 'In')

It’s not exact but I think it’s good enough

The easing is from easings.net

1 Like

The code does technically make a bounce effect, however, how can I make it higher even though stepy1 goes up in the y axis by 5 studs (yeah, I could switch 5 but that’s not really easy to keep track of, right?)