[SMART PEOPLE REQUIRED] How could I add speed/velocity everytime a part bounces?

im not sure if the title is correct, cause this could be pretty simple but how could I detect when a part bounces, and make it bounce higher and higher? I assume you could do this with raycasting however there may be other ways. Thanks!!!

When a part bounces its velocity changes rapidly and will rebound in the other direction, being that it is in the other direction the velocity will be negative if its already positinlve or positive if its already negative.

Just monitor the velocity and when it suddenly changes in the other direction add to that velocity to make it bounce higher.


sure, but how should i detect when it “suddenly changes”

So if you were to do a loop every say .05 of a second, if something flips the velocity in that time it would definatly be considered a rapid change.

Of course 0.05 does mean looping 20 times a sec but its basic checks and you could even adapt the looptime as the script is running based on frequency of rapid changes.

Use the part’s Touched event. When the part in question touches anything, this event will fire. You can add a task.wait() or task.wait(0.05) to wait for physics to update the velocity then you can do what ever you want with it.

Touched is not good, its dodgy and doesnt consistantly activate not to mention added delays and speed caps. Although just crossed my mind, if its bouncing it would rewuire a collision to occur anyway. Touched could work but i still dont recommend.

1 Like

If it’s ONLY one part, then you can poll it without affect server performance too much as you stated. But if it’s a bunch of parts, then you have to use Touched because to pool more than a few parts will negatively affect server performance. Besides, I use Touched all the time. Seems to work fine for me.

so everytime something bounces, what will happen to the velocity? for example, a ball falls straight down, once it lands will the Y go negative?

while true do
if ball.Velocity --how could i detect if X is negative or Y or Z?

the thing is, if the ball goes very fast bouncing against a ton of walls, tounched probably wont fire due to it being slow.

Greater than or less than 0. Also for basic checks you can run over 1k of them no problems. I douvlbt yoyr need over 1k bouncing parts though.

so would this work?

	if ball.Velocity.X < 0 or ball.Velocity.Y < 0 or ball.Velocity.Z < 0 then
    ball.Velocity += ball.Velocity

Touched would still fire at low speed, its the high speeds it doesnt like. But even if you get a touched event there could be another .05 delay before actually being able to do anything as well as still needing to add a negative or positive number to your velocitys axis. Overall yes it could be used to gey the desired outcome but not without a ton of issues and limitations.

That would just rapidly accelerate. You would want to check if it changes from positivr to negative so have a variable holding the last velocitys negative or positive as bools and then compare the current to see if its changed then add velocity based on thay.

thats what i literally said, when i said “slow” i meant touched being slow

then what should i change?

Since you want it to bounce, there are multiple ways to do this. You can multiply the Y velocity or use BodyMovers.

i know how to make it bounce, i just want to find out how to detect the bounces

If you were to use BodyMover, you can use .Touched or Region3 for hit detection. And if a character were to touch your part, you can check if there is a BodyMover on the character.

According to physics, gravity always accelerates towards the largest mass according to this formula:

P = 1/2at^2 + vt + y where
	a = gravimetric acceleration
	t = time
	v = initial velocity
	y = starting position (height)

I’m not sure, but I think Roblox defines their velocity to be +up. That means that if you are moving from the reference plane up, your velocity will be positive. So if you are falling towards the gravity, you would have negative velocity. It all depends on the definition of the inertial reference frame. Because of this, the Y velocity component would constantly change magnitude because of gravity. Perhaps you are looking to apply a force instead?

This is more gravity and relative mass and relative direction and velocity. To even begin to use this they would need complete understanding of cframes.

Also that equation there wont do you any good even if you are trying to change gravity, its no different from using 9.81 in a grav formula ahaha. Anyway, lets stay on topic here.

I just read that the OP want to detect bounces only. The question becomes how fast are the bounces happing? I made a grenade launcher that uses the touched event to play a metallic bounce sound. Towards the end of that it’s skittering at like 10-20 bounces a second before it settles then blows up. If it’s more than that, then a poll solution may be better. IIRC, task.wait() has a time of 1/60th of a second or something like that.