So I apologize if I over-explain this.
I’m creating a bouncing without using gravity or physics materials. Right now there are five possible spots on the x-axis where a ball is able to be (on the x-axis the spaces are -2.5, -1.25, 0, 1.25, 2.5) the ball bounces up in the y-axis and is unaffected by z.
After an initial bounce, the ball is able to go to any of the 5 spaces outlined on the x-axis. The balls will travel in a curve and land on one of the 4 other possible spaces. It’s also set up to go down on the y-axis to -5 (the paddles that intercept the ball are laid out on -3 on the y-axis) so the objective of the game is to move the paddle to one of 5 spots to intercept the ball. For an example of this is, when a ball hits a paddle in one of the spots, it will travel from (-2.5, -3, 0) to (1.25, -5, 0)
However, because I have the balls going all the way down to -5 on the y-axis the spots where the paddle intercepts the ball are not in the middle of one of the points on the x-axis I outlined earlier (-2.5, -1.25 etc.), They end up being either short or over-extended where they should be because they need to travel the extra 2 to reach -5.
Setting the y value on the bounced position from -5 to -3 or so fixes the problem but then the animation ends and the ball doesn’t descend further. The solution I’m trying to figure out is instead of bouncing it on the x-axis on one of the bounce positions I outlined earlier (-2.5, 1.25 etc.), instead of aiming for one of the x-axis values directly, plot an imaginary point at -5 where the paddle space would intercept the ball. However, I don’t have the foggiest on the math I would need to calculate the x value of that imaginary point.
This is the code I’m using to plot the point currently
endPos = new Vector3 ((paddleSpaces [nextSpace].GetComponent<Transform> ().position.x), -5f, 0f);
Where paddleSpaces is an array of GameObjects containing the five spaces, nextSpace is a random number between 0 and 4.
And this is what I’m using to calculate the curve animation
while(Time.time < timeStamp + (bounceTime/gc.speedCo)){
Vector3 currentPos = Vector3.Lerp(startPos, endPos, (Time.time - timeStamp)/(bounceTime/gc.speedCo));
currentPos.x += bending.x * Mathf.Sin (Mathf.Clamp01 ((Time.time - timeStamp) / (bounceTime/gc.speedCo)) * Mathf.PI);
currentPos.y += bending.y * Mathf.Sin (Mathf.Clamp01 ((Time.time - timeStamp) / (bounceTime/gc.speedCo)) * Mathf.PI);
currentPos.z += bending.z * Mathf.Sin (Mathf.Clamp01 ((Time.time - timeStamp) / (bounceTime/gc.speedCo)) * Mathf.PI);
transform.position = currentPos;
if (bounced) {
yield break;
}
yield return null;
}
Please, any help that you guys can offer me in this would be greatly appreciated. I confess I’ve been stuck on this problem for a couple days and my different attempts to solve it have not gotten me very far.
Thank you.
,