Are the objects falling vertically or diagonally? It makes a big difference in the complexity.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
Isn't this basic math? If you know the terms (slope, axis, etc) you already know (or can find) the correct equations. Turn them into code.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
I don't see any struggle at all. You have posted no code whatsoever.
An equation is an equation. If you've done any C++ you've done an equation, haven't you? + - * / ?
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
If they're falling vertically, all you need to do is take the X-coordinate of the projectile and plug that into the equation that defines the "surface". Once the projectile's Y-coordinate matches the solution for the equation, you have impact. This, of course, ignores any radius on the projectile.
Just break the algebra down into smaller sub-problems then write your statements to solve the sub-problems. Once you have those, combine them into the final solution. I'm sure you're familiar with the slope-intercept method (y=mx+b). If you already know m and b, you're all set, just plug in and solve. You can still find the solution algebraically even if you only know 2-points.
We really can't offer better information unless we know what you already do or don't know.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
Just imagine a ball falling in an uneven ground. Before the ball hits
the ground, you have to know some information. Its (x,y) position. Its
velocity vector. Its mass. And so on depending how detail the object is represented. As suggested, if the ball falls vertically, then you just take
its x position. This x position of where the ball is at time t, when falling
will be the same as the point of impact. Thus as suggested, you can just
get the terrain's height from the x position of the ball. Now all you
have to do is calculate the new velocity vector of the ball after the point
of impact. If the ball is falling from any angle, then it will be almost be
the same solution. You use the ball.x position. The calculation for the
velocity vector after the point of impact will be a little different.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
We knew you wanted code suggestions, but without a starting point from you we really couldn't help any more than we tried to. Glad you figured it out.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393