Original Post
Hi there i''m new to the idea of projectile motion and is trying to create a simple projectile application called cannon. Now, i''ve read and tried all of the forums messages on GameDev.net.
My problem is getting one of them to work.
All i want is the user should set an angle, set an initial charge and click a button to see the tragectory in motion.
I''ve declare gravity as-> private double gravity = 9.8;
below is the code i wrote to fire the cannon ball. I tried the code with an angle of 50 degrees and an initialvelocity of 100 and the ball only move a little bit. If the set the initialvelocity of 1000 the ball never comes down.
Can some body please help, i''m going crazy on this.
Thanks
James
private void btnFire_Click(object sender, System.EventArgs e){
initialiseBallPosition();
angle = ConvertDegreesToRadians((double)this.trackBar1.Value);
double inc = 1.0;
double dt = inc / 60.0;
initialVelocity = (double)this.numericUpDown2.Value;
xVelocity = initialVelocity * Math.Cos(ConvertDegreesToRadians(angle));
yVelocity = initialVelocity * Math.Sin(ConvertDegreesToRadians(angle));
ballX+=(int)xVelocity;
ballY+=(int)yVelocity;
yVelocity-=gravity;
int i = 0;
const int SLEEP_TIME = 10;
do
{
Thread.Sleep(SLEEP_TIME);
Application.DoEvents();
ballX+=(int)(xVelocity * dt);
ballY+=(int)(yVelocity * dt);
yVelocity-=gravity*dt;
Invalidate();
i = i + 1;
}while(i < 20);
}