My goal is to do something like this: https://imgur.com/a/o4HaceP
This is what a got so far(just the line stopping to draw when detect a ball): https://imgur.com/a/rm8rStf
I'm using physics module in balls and table.
I don't have idea how to do it, could someone help me?
update1: https://imgur.com/a/FEmRLOd I managed to do the collision detection by using rayCast in a double sized ball shape, but could not get the angles right.
Help with calculating trajectory
Help with calculating trajectory
- Attachments
-
- RogueCue_update1.love
- (440.47 KiB) Downloaded 375 times
-
- RogueCue.love
- (439.98 KiB) Downloaded 395 times
Re: Help with calculating trajectory
See if you can work with ChatGPT for it to explain vector reflection for you.
You have the incoming vector and it's being reflected on the normal of a surface (like the surface of a ball, or the surface of the boundaries of the table).
To find the reflected vector, you flip the direction of the incoming vector, project it onto the normal, then get the rejection (the difference between the flipped incoming vector and its projection onto the normal) and add that rejection twice to the flipped incoming vector.
This will place you on the reflected position.
Image taken from this article here:
https://www.fabrizioduroni.it/2017/08/2 ... on-vector/
On that image L is the (flipped) incoming vector, N is the surface normal, N' (the red arrow) is the projection of L onto N, and U' or U'' is the result of (L - N') AKA the rejection of L onto N.
So if you take L and add twice U (or subtract U, it depends on the sign of U given by how you calculated U), this will give you R, the reflected L onto N.
Other resources (in this order, since the first ones explain projection):
You have the incoming vector and it's being reflected on the normal of a surface (like the surface of a ball, or the surface of the boundaries of the table).
To find the reflected vector, you flip the direction of the incoming vector, project it onto the normal, then get the rejection (the difference between the flipped incoming vector and its projection onto the normal) and add that rejection twice to the flipped incoming vector.
This will place you on the reflected position.
Image taken from this article here:
https://www.fabrizioduroni.it/2017/08/2 ... on-vector/
On that image L is the (flipped) incoming vector, N is the surface normal, N' (the red arrow) is the projection of L onto N, and U' or U'' is the result of (L - N') AKA the rejection of L onto N.
So if you take L and add twice U (or subtract U, it depends on the sign of U given by how you calculated U), this will give you R, the reflected L onto N.
Other resources (in this order, since the first ones explain projection):
Re: Help with calculating trajectory
If you don't want to do any of the math, then you can just simulate the shot. Take the table, the cue stick and the balls into an separate physics environment, do the shot there and if the white ball hits any other ball, then you have all the information you need to draw what you want: At the moment of impact you can draw where the white ball is. And if you simulate for a small amount of time afterwards you can draw the lines, where the balls will go.
You just need to be careful about secondary impacts. But those can be removed if you just simulate the cue stick, the white ball and the ball that was hit - e.g. in a second run (or another separate physic environment).
You just need to be careful about secondary impacts. But those can be removed if you just simulate the cue stick, the white ball and the ball that was hit - e.g. in a second run (or another separate physic environment).
Re: Help with calculating trajectory
Do you think the way I did is going to work? Like im not getting the normal from the ball itself, im getting from a invisible ball that has the double radius of the red ball.RNavega wrote: ↑Thu May 30, 2024 8:44 pm See if you can work with ChatGPT for it to explain vector reflection for you.
You have the incoming vector and it's being reflected on the normal of a surface (like the surface of a ball, or the surface of the boundaries of the table).
To find the reflected vector, you flip the direction of the incoming vector, project it onto the normal, then get the rejection (the difference between the flipped incoming vector and its projection onto the normal) and add that rejection twice to the flipped incoming vector.
This will place you on the reflected position.
Image taken from this article here:
https://www.fabrizioduroni.it/2017/08/2 ... on-vector/
On that image L is the (flipped) incoming vector, N is the surface normal, N' (the red arrow) is the projection of L onto N, and U' or U'' is the result of (L - N') AKA the rejection of L onto N.
So if you take L and add twice U (or subtract U, it depends on the sign of U given by how you calculated U), this will give you R, the reflected L onto N.
Other resources (in this order, since the first ones explain projection):
(the point of contact is the green ball)
Re: Help with calculating trajectory
I think this is more complicated than math and a little bit janky hahahaXugro wrote: ↑Thu May 30, 2024 9:43 pm If you don't want to do any of the math, then you can just simulate the shot. Take the table, the cue stick and the balls into an separate physics environment, do the shot there and if the white ball hits any other ball, then you have all the information you need to draw what you want: At the moment of impact you can draw where the white ball is. And if you simulate for a small amount of time afterwards you can draw the lines, where the balls will go.
You just need to be careful about secondary impacts. But those can be removed if you just simulate the cue stick, the white ball and the ball that was hit - e.g. in a second run (or another separate physic environment).
Re: Help with calculating trajectory
I think using the invisible ball with doubled radius is not going to work.betobala wrote: ↑Thu May 30, 2024 10:40 pmDo you think the way I did is going to work? Like im not getting the normal from the ball itself, im getting from a invisible ball that has the double radius of the red ball.RNavega wrote: ↑Thu May 30, 2024 8:44 pm ...
To find the reflected vector, you flip the direction of the incoming vector, project it onto the normal, then get the rejection (the difference between the flipped incoming vector and its projection onto the normal) and add that rejection twice to the flipped incoming vector.
This will place you on the reflected position.
...
(the point of contact is the green ball)
For an obvious example think of a shot where the balls closely miss each other. But with doubled radius they could touch.
Another problem is that the vector is more simplified than the collision handling of Box2D/love.physics.
Box2D simulates things like spin of the balls and friction which can produce different results.
Re: Help with calculating trajectory
Do you know any possible solutions for that? Im just a beginner with game dev and can not think in any solutionknorke wrote: ↑Thu May 30, 2024 11:12 pmI think using the invisible ball with doubled radius is not going to work.betobala wrote: ↑Thu May 30, 2024 10:40 pmDo you think the way I did is going to work? Like im not getting the normal from the ball itself, im getting from a invisible ball that has the double radius of the red ball.RNavega wrote: ↑Thu May 30, 2024 8:44 pm ...
To find the reflected vector, you flip the direction of the incoming vector, project it onto the normal, then get the rejection (the difference between the flipped incoming vector and its projection onto the normal) and add that rejection twice to the flipped incoming vector.
This will place you on the reflected position.
...
(the point of contact is the green ball)
For an obvious example think of a shot where the balls closely miss each other. But with doubled radius they could touch.
Another problem is that the vector is more simplified than the collision handling of Box2D/love.physics.
Box2D simulates things like spin of the balls and friction which can produce different results.
Re: Help with calculating trajectory
Knorke's point that Box2D might cause things to behave in a way that differs from your vector prediction is important. Some testing is needed to confirm this.
I think it should work because we're talking about the initial impulses or collisions (the direction in which the balls will start moving), not their final positions.
Your way of finding where the white ball will hit the colorful ball is pretty clever with raycasting that imaginary green circle.
The surface normal in that case can be found by going from that raycast point down to the colorful ball center. It's the same as the surface normal of the colorful ball:
The white ball is coming in by the orange arrow and gets reflected by the normal to become the blue arrow (edit: and the colorful ball moves along the opposite of that surface normal after the white ball hits it, so it's opposite to the teal line).
Re: Help with calculating trajectory
Thanks everyone, I will try to apply this, hope I get it, I have zero experience calculating vetors
Re: Help with calculating trajectory
I'm trying to invert the normal line, but i can not do it, do u have any tips to help me calculate that?RNavega wrote: ↑Fri May 31, 2024 12:53 amKnorke's point that Box2D might cause things to behave in a way that differs from your vector prediction is important. Some testing is needed to confirm this.
I think it should work because we're talking about the initial impulses or collisions (the direction in which the balls will start moving), not their final positions.
Your way of finding where the white ball will hit the colorful ball is pretty clever with raycasting that imaginary green circle.
The surface normal in that case can be found by going from that raycast point down to the colorful ball center. It's the same as the surface normal of the colorful ball:
temp2.png
The white ball is coming in by the orange arrow and gets reflected by the normal to become the blue arrow (edit: and the colorful ball moves along the opposite of that surface normal after the white ball hits it, so it's opposite to the teal line).
Who is online
Users browsing this forum: Ahrefs [Bot] and 8 guests