Jump to content
  • Advertisement
Sign in to follow this  
Godden

Changeing sphere direction

This topic is 5106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I am working on a assignment were i have a ball inside a cube. The ball moves and collids with the faces of the cubes. This is how i break my problem down atm. the ball intitaly starts falling due to gravity at say -0.1y it will then hit a face of the cube. To find the deflection u take the normal and the distance between the normal and the vector (say theta) that the sphere is coming in on. this is were i become lost. how can i use this angle and the current magnitude to keep the same speed with a reflection of the normal so it heads of in theta from the normal. This is in 3d so there will be x y and z.

Share this post


Link to post
Share on other sites
Advertisement
if normal is N and vector is V, reflected vector is
V-2*N*(N dot V)
where dot is dot product.
To find collision with plane you just need to check if sphere center is closer than radius.

Share this post


Link to post
Share on other sites
Its just bounce up and down it doesnt change direction ?

[Edited by - Godden on October 23, 2004 5:31:06 AM]

Share this post


Link to post
Share on other sites
Project the balls velocity vector onto the cube plane normal using:

float proj = vel.DotProduct(normal)

then minus twice the plane normal scaled by the above value from the balls velocity:

vel -= 2*normal*proj

Exactly as Dmytry says

Quote:
V-2*N*(N dot V)


If this doesn't work its likely a bug in your code

Share this post


Link to post
Share on other sites
It bounces up and down because it is travelling parallel to the normal. If you drop a ball straight down on a level floor it should bounce straight up in a perfect world.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!