How to make object bounce

Hello! I have a game where you shoot things. I’m pretty good with CFrames and I use bodyVelocity for the shooting thing. I want to know how to make the object detect which side is touched and can turn in response. For example in this picture:




Any help would be appreciated!

2 Likes

you can put a part to all side and put a touched event script inside , make sure the part canCollide is false .

Is there another way that is less laggy? Because it’s very laggy and it has errors where hit is nil.

just make the velocity of the ball the opposite side…aka making it a -velocity

Can you give me an example please? Like do you say

bodyVelocity.Velocity = -(bodyVelocity.Velocity)

?
Thank you so much!

Do you have any code yet???

Quite confused are you trying to reflect the part from the point where it hit?

1 Like

Yes I want to make it reflect when it hits the part. And yes, I do have code but it doesn’t work so I have to start over but I have the code that makes it turn backwards but it’s not what i want i want it to bounce according to it’s degree it touched. Like when it kind of scrapes a part i want it to turn away a little like in real life physics but if it’s almost like a head-on collision i want to make it also bounce backwards. Thanks!

You could basically use Raycast and Debris. Raycast.Instance to detect the hit part and Debris to remove after a certain time.

Um no I already handles if the part touches it get destroyed but I’m working on an upgrade that you can buy to make your shooting things not get destroyed and can bounce. Can you explain a bit more about raycasts? Thanks!

Lemme think. After the object touches a part you want to make the part bounce right?

Yes. And it must also depend on the angle it touched so that if it just scraped another part then i want it to turn a little like in real life physics but if it’s head-on collision, i want it to turn backwards more like in real life physics. Thanks!

How to reflect rays on hit You could raycast, and reflect the ray and move the ball in the direction of the new ray.

Ok. But it’s a bit hard to understand. Can you help me a bit more? Like give me a sample code. Variable i have:

hit - the part that touched
fireball - the shooting thing
bodyVel - the body velocity which is parented to the fireball

They are all working right now btw.
TYSM!!