Ball Bouncing System

I am trying to make a ball bounce off a block. I cannot get it to work though, I’ve tried it with BodyVelocity and BodyForce, I’ve tried it with Instance.new() and even with them already there.

Please let me know if you can find the issue.
This is my code:

	if otherPart.Name == "Bouncer" then
		local move = Instance.new('BodyVelocity')		
		move.MaxForce = Vector3.new(1,1,1) * math.huge
		move.Velocity = script.Parent.CFrame.upVector * 100
	end	
end
1 Like

It looks like the problem is that you’re not parenting the new BodyVelocity to the part you want to move. Being parented to the part is how the Body movers work. Don’t forget about the new constraints system though, they can work as well or even better!

2 Likes

Ohhh, yea that makes sense. Let me try that.

	if otherPart.Name == "Bouncer" then
		local move = Instance.new('BodyVelocity')
		move.Parent = script.Parent		
		move.MaxForce = Vector3.new(1,1,1) * math.huge
		move.Velocity = script.Parent.CFrame.upVector * 100
	end	
end

Would this make sense?

This is correct, a simple fix would be…

	if otherPart.Name == "Bouncer" then
		local move = Instance.new('BodyVelocity', otherPart) -- The parent is just a guess from the context of your code, feel free to change it!
		move.MaxForce = Vector3.new(1,1,1) * math.huge
		move.Velocity = script.Parent.CFrame.upVector * 100
	end	

Okay, I’ll try that. Thanks for the help!

Typically you want to parent last when adjusting your parts, and not in the Instance.new function itself. So

if otherPart.Name == "Bouncer" then
	local move = Instance.new('BodyVelocity')	
	move.MaxForce = Vector3.new(1,1,1) * math.huge
	move.Velocity = script.Parent.CFrame.upVector * 100
	move.Parent = script.Parent	
end	

The reason for this isn’t something I can remember off the top of my head, but I read that it’s faster for the game to process, and it’s basically to no cost for the programmer’s time, so its good practice to do it this way.

None of these seem to work, would it be in a regular or local script?

Normal scripts run on the server. Local scripts run on the client. Putting it in a local script for the client would work but it would only show on the client and not replicate to the server and other clients, and the movement of it would only replicate if the client is the NetworkOwner (the client/server the simulates the physics for a part). It’s up to you what you use for your needs, but most likely it would be on the server. Either way it should show up when you press play and spawn in regardless.

I am incredibly sceptical if this is a good way to make things bounce. I would recommend using VectorForces instead or even just use the default Custom Physical Properties and change the density and elasticity or the ball.

Even the new function that works ApplyImpulse.

links:

1 Like

Alright, I’ll check that out. Thanks.

1 Like

Egomoose has an amazing tutorial on calculating this. Warning: it has math

Good luck!

Maybe I should have mention this in the beginning but its for a ping pong ball for ping pong that can be played with an “AI” which is basically just a wall that the ball bounces off of, I’ve just tested this but it does not seem to have enough momentum to keep a game going.

Are you sure about that? Just tweaking some parameters you should be able to get something to bounce infinitely. https://gyazo.com/358aee5921110139854f7e414f0c6abf

Not when the ball it is bouncing of an angled part.

What are your settings for that video?

The spawn that is at the bottom has elasticityWeight set to 0 and the Ball elasticityWeight is 1.That is to make sure the ball is bouncing off the ground and not the other way around.

I set the elasticy of the ball to 1. I set the density to 10 so that it will be affected less if something else hits it but you don’t need to…

In theory the ball will bouncy forever however due to floating point inaccuracies it might last for a couple of days-weeks or so. Maybe more maybe less that’s just a guess.

Oh and I set both friction to 0 just incase.

https://gyazo.com/480c53202ca2bb9b55510c477fb16cc4
This is actually very fun to watch lol.

4 Likes

I got it working but now im experimenting with bouncers to get a full ping pong game played with “AI” and then make it so the player can play.

2 Likes