- Home /
Ball landing point calculation only returns positives?
So I have a landing point calculation for the most part working. However, it's only returning positive numbers...when the ball itself moves both ways, X/-X. The game plays out in X/Y coordinates, with locked Z - this is all 2D.
I know I'm on the right track, but I'd really like it to also return negative coordinates. What am I doing wrong in my code? To be honest, it's probably something really stupid!
Vector3 BallMinder = BallPosition.position;
float BallX = BallMinder.x;
float BallY = BallMinder.y;
float GroundHitPointX = (BallX + BallY);
Addtional Information: The ball moves by pure gravity and physics. No additional forces are added aside from impacts it may take, which are not coded. X serves as position, Y serves as time until the ground.
Uhm, sorry, but that code makes no sense at all. First of all it looks like all you have as input parameters for your "calculation" is a single position of an object. Where is the movement? Next thing is adding the x and y coordinates together doesn't result in any meaningful value.
How is your ball actually moving? Do you use physics or do you move it "manually"? If so post the code that moves / shoots the ball. Without more details we can't help you as the code simply doesn't make sense.
I'm a little confused as to why you say it doesn't make any sense. It works. It's all physics-based, the ball drops and is moved by impact. No forces aside from gravity. It is in fact calculating a landing point that is mostly accurate, but it won't provide negative results. Y acts as the time until it takes to hit the ground, X is the current position. BallPosition is.... -should- be obvious. It is the transform.position of the ball in motion.
The trajectory of a ball that has an initial speed and experiances gravity (or another linear acceleration) is a parabola. You might be lucky that the position is "mostly accurate" but your formula has no relation to the actual movement. Again you don't even have any movement in your calculations. What do you actual mean by impact? Does that mean the ball hits some kind of slope and bounces to the side? Could you include a screenshot of your setup since your short description doesn't really help what is happening.
(I'm off now, so don't expect an answer anytime soon ^^. I'm back in about 8h)