Jump to content
• ### What is your GameDev Story?

• Advertisement

# Changeing sphere direction

This topic is 5204 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

##### 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

##### Share on other sites
thanks ill just give it a try i forgot to say i knew how to find the collision :D

#### Share this 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

##### 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

##### 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

##### Share on other sites
BTW, if you want it to bounce lower(not too high),
V-k*N*(N dot V)

where 1<k<2
(use k=1.8 or so)

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 11
• 9
• 9
• 42
• Advertisement
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015715
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!