protek
"Takai desu ne." -"Jinsei da."
Here's one for you physics and maths wizs.
I'm programming the old Nintendo Game&Watch Snoopy Tennis on XNA. Instead of moving the balls in steps, I've found a formula that gives a natural looking smooth trajectory. The problem however is that I can't get the ball behave correctly, when Snoopy hits it.
These two lines define the initial trajectory, when Charlie passes.
The lines are run for each ball instance's Update method. MovingPosition is the ball's current position. StartPosY and X are the starting positions. Velocity is a double constant of 88. Angle is a single dimension table and it is randomly selected from three first entries in the table, giving three different trajectories. Acceleration is a float set to -9.8 to represent gravity.
So Charlie basically passes all balls nicely to the three points, where Snoopy is supposed to hit them. I already have collision detection implemented, so the hit is detected. Problem is I don't know how to make it bounce from the racket.
If I just simply change the trajectory value or startpos values, the ball seems to teleport somewhere else, when it's been hit. I basically needed to get the ball bounce from the racket and head towards the platform over Charlie, where Lucy might hit it back.
Any ideas?
Below is a pic of the Nintendo version:
I'm programming the old Nintendo Game&Watch Snoopy Tennis on XNA. Instead of moving the balls in steps, I've found a formula that gives a natural looking smooth trajectory. The problem however is that I can't get the ball behave correctly, when Snoopy hits it.
These two lines define the initial trajectory, when Charlie passes.
Code:
MovingPosition.Y = (float)(StartPosY + Velocity * Math.Sin(Angle[Trajectory]) * time - Acceleration * time * time / 2);
MovingPosition.X = (float)(StartPosX + Velocity * Math.Cos(Angle[Trajectory]) * time);
The lines are run for each ball instance's Update method. MovingPosition is the ball's current position. StartPosY and X are the starting positions. Velocity is a double constant of 88. Angle is a single dimension table and it is randomly selected from three first entries in the table, giving three different trajectories. Acceleration is a float set to -9.8 to represent gravity.
So Charlie basically passes all balls nicely to the three points, where Snoopy is supposed to hit them. I already have collision detection implemented, so the hit is detected. Problem is I don't know how to make it bounce from the racket.
If I just simply change the trajectory value or startpos values, the ball seems to teleport somewhere else, when it's been hit. I basically needed to get the ball bounce from the racket and head towards the platform over Charlie, where Lucy might hit it back.
Any ideas?
Below is a pic of the Nintendo version: