How can I make this part bounce while moving?

Hello, I have been making a pet that moves randomly but I want it to bounce, I tried using tween service to make the part go up and down but it only works when the part is not moving here is my script that makes it move randomly:

local ts = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	0
)


while true do
	wait(5)
	ts:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(math.random(-20, 30),0,math.random(-10, 10))}):Play()
end

How can I apply bouncing to it?

Thank you!

1 Like

EDIT: The way I was making it bounce is the same way I just did this:

local tweenService = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
	.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	-1,
	true,
	0
)
local tweenInfo2 = TweenInfo.new(
	.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local tween = tweenService:Create(script.Parent, tweenInfo, {CFrame = script.Parent.CFrame + Vector3.new(math.random(10,40),3,math.random(10,60))})

tween:Play()

But it does not work when its moving.

I think you could use Enum.EasingStyle.Bounce to make the part bounce whilst moving if that’s what you’re referring to

2 Likes

I tried it too but here is what happens:


As you can see it’s very buggy when I add the bouncing script

3 Likes

Not sure if it’s related, but in your TweenInfo that you set up to the Create function, you set repeatAmount to -1, meaning it’ll infinitely repeat

2 Likes

I did this but it does not move it just bounces:

local ts = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	0
)


while true do
	wait(5)
	ts:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(math.random(-20, 30),0,math.random(-10, 10))}):Play()
	ts:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(0,3,0)}):Play()

end
1 Like

Probably a tween overwrite? Try this out

local ts = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Bounce,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)


while true do
	wait(5)
	ts:Create(script.Parent, tweenInfo, {Position = script.Parent.Position + Vector3.new(math.random(-20, 30),3,math.random(-10, 10))}):Play()
end

Yes, but I want it to move while going up and down like a simulator pet, here is what happens:

I think that’s because the true in your TweenInfo means it’ll reverse at the end, did yu try my edited code?

1 Like

Yeah I tried it but it goes up and never goes down

I found this picture that explains what I want:

I’m trying to see how I coulddo what you want, so far I’m only getting the bobbing bit to work. When I try to make it tween whilst bobbing, it causes a slight y axis increase which you probably odn’t want. I managed to get a slight version working using a botched together bounce system. I’m not sure what the intended way of doing it is, I think it may be better to wait for someone who knows what they’re doing in this case, but I don’t think it is possible for you to be able to do bouncing whilst a tween is going on, unless you create a new tween every frame

1 Like

can you use math.sine???

1 Like

I mean it’s all I need for now I’ll try to improve it