Jump to content
  • Advertisement
Sign in to follow this  
UkLearner

Help need for Projectile motion

This topic is 3493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have developed a Ball shooter game and i also applied Projectile motion i am trying to write a methord to use physic formule for ball Projectile motion. anyone can you help me to correct the problem? The code i writen is for what need to be happen when i press spacer bar or enter is if ((keybstate.IsKeyDown(Keys.Enter)) || (keybstate.IsKeyDown(Keys.Space))) { //double velocity = (double)Players[currentPlayer].Power; //double accelaration = -9.80; //double getAngle = (double)Players[currentPlayer].Angle * 3.14; //double Vx, Viy, Vfy, t, d; //Vx = velocity * Math.Cos(getAngle); //Viy = velocity * Math.Sin(getAngle); //Vfy = -Viy; //t = (Vfy - Viy) / accelaration; //d = Vx * t; //Console.WriteLine("Vx: " + Vx); //Console.WriteLine("ViY: " + Viy); //Console.WriteLine("Time: " + t); //Console.WriteLine("Distance: " + d); ballFlying = true; ballPosition = Players[currentPlayer].Position; ballPosition.X += 7; ballPosition.Y -= 38; ballAngle = Players[currentPlayer].Angle; Vector2 up = new Vector2(0, -1); Matrix rotMatrix = Matrix.CreateRotationZ(ballAngle); ballDirection = Vector2.Transform(up, rotMatrix); ballDirection *= Players[currentPlayer].Power / 50.0f; } and the ball update methord private void UpdateBall() { if (ballFlying) { Vector2 gravity = new Vector2(0, 1); ballDirection += gravity / 10.0f; ballPosition += ballDirection; ballAngle = (float)Math.Atan2(ballDirection.X, -ballDirection.Y); for (int i = 0; i < 5; i++) { Vector2 smokePos = ballPosition; smokePos.X += randomizer.Next(10) - 5; smokePos.Y += randomizer.Next(10) - 5; smokeList.Add(smokePos); } } } so can you anyone help me to re-write the function for ball Projectile motion in using physic formule, i try to use the formule but i dont know how to update the ball by using the formule. e.g. double velocity = (double)Players[currentPlayer].Power; double accelaration = -9.80; double getAngle = (double)Players[currentPlayer].Angle; double Vx, Viy, Vfy, t, d; Vx = velocity * Math.Cos(getAngle); Viy = velocity * Math.Sin(getAngle); Vfy = -Viy; t = (Vfy - Viy) / accelaration; d = Vx * t; So the Projectile motion is done in different way but i need to do using the physic formule. so can you anyone help me once after we know the angle, how would be to take the sine and cosine of this angle and use this as Y and X components in my methord explained above?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!