#### Archived

This topic is now archived and is closed to further replies.

# Billiard and Ball, how to handle?

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

## Recommended Posts

Hello all, I''m trying to create a billiard game using DirectX. I''m drawing a line from the ball to the direction i want to shoot the ball to. This is like every snooker/billiard/pool game. It''s 2D by the way, from top view. My question is, how to change the X and Y of the ball every time? I mean, the speed of the ball is related to the lenght of the line that i''m drawing. Or not? That''s just basic Pythagoras.... But then you have the speed of the ball.... What to do with that? I''m now doing it like this: the difference between X1 and X2 (of the line) is the direction that the ball must travel in X. the difference between Y1 and Y2 (of the line) is the direction that the ball must travel in X. That''s all. The bal is going to the right direction, but i don''t think that''s the good solution. I''m not working with angles at all. I think i must use angles.... I just want to shoot the ball in the right direction at the right speed. Can somebody help me, sorry for my poor explanation... Mosselmaniac

##### Share on other sites
I don''t think you need to use angles. you are on the right track, you need to learn about vector normalisation,
from what I understand you have a vector for direction, but you need to apply a speed to it.
Normalizing a vector means making its length one unit (unit vector), the code to do this in 3d code be:

void Normalize(float &vec[3]) {
float length;

length = Length(vec);

// error protection
if (length == 0.0f) {
length = 1.0f;
}

vec[0] /= length;
vec[1] /= length;
vec[2] /= length;
}

You can then multiply this vector by your float speed.

I hope this helps

##### Share on other sites
Uhm not sure what you''re asking for but I think you''ll need to learn some basic mechanics. What level of maths/physics are you at? You''ll need to know newton''s laws for handling ball collisions, I doubt there''s an accurate way of simulating momentum, forces and acceleration by tricks.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631413
• Total Posts
2999945
×