# Simulating a Rebounding Cube?

Hey There! I’m trying to use BodyMovers to make a rebound effect with a projectile.

I have a ball which I am giving the force so that it will hit a wall with angle Theta, as shown below (the blue angle).

My problem is “How do I find the angle of collision?”

I’ve read some posts about this, and one said “Raycast it to the wall and then find :Dot()”. I get that, but how do I get the direction of the ray I have to cast?

If I get the angle of collision, I can flip it and raycast to the flipped direction, and then use BodyPosition to get it there, however the start is where I’m having a problem. Thanks for the help!

EDIT 1:

I have managed to make a part which uses CFrame.LookAt to visualize the angle to incidence.

https://gyazo.com/c2e4ba81d7241962db285bdf1d1fc3

I’m not sure how to actually get the angle in vectors tho

1 Like

You might get interested in LookVector which is a property of CFrame to find out the direction of the ray that you are to cast.

Or if your cube relies on physics so you cannot predict the rotation of the cube, you should get direction by subtracting the previous position of delta time beforehand from the current position.

1 Like

You can get the direction you want with a raycast with this simple formula:

rayDirection = rayDestination - rayOrigin

Agreed, but to the get the RayDestination, I need a raycast lol

That’s a good way, but a little unreliable if the object’s path is unevenly curved.

Good point, you can the velocity the ball is going with and use that as your rayDirection. So like, if the velocity = Vector3.new(0,500,0) then Vector3.new(0,500,0) is your rayDirection.

1 Like

Since you could use Stepped and update position every 1/60 of a second, it should be reliable even if object is curving dynamically.

1 Like

Oh that’s smart. I’ll check it out. (I’m using bezier curves, so your method is very helpful!)

Wow I didn’t know that. I’m gonna read more about direction of velocities to implement your method, but thanks!

I’m a mod .!?.!?.!?.!?.!?.!?.!?.!?.!?

1 Like