Results 1 to 5 of 5

Thread: [RESOLVED] Solving s = 1500sin(theta).cos(theta)

  1. #1

    Thread Starter
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Resolved [RESOLVED] Solving s = 1500sin(theta).cos(theta)

    As part of the AI i've just started for a game I'm making, I need to make the AI figure out the best angle to shoot at. My game looks something like this at the moment (heavily cropped):[IMAGE DELETED]
    As you can see, there are 2 cannons shooting across the screen at eachother, with a wall in the middle to shoot over.
    In the game the players use the keys to aim up and down, and move left and right. So the players are aiming at an angle, theta, and when they shoot the bullet is given an XVel (horizontal) of 15 * cos(theta) and a YVel (vertical) of 15 * Sin(theta). [In case you're wondering, the yvel value is subtracted from the bullets Y value every game loop, to account for the top-left origin]. The game loop runs every 10 m/s, with gravity accelerating downwards at a rate of 0.3. So by my reckoning:
    u = 15*sin(theta)
    a = -0.3
    v = 0
    t = time taken to get to peak, which is what I'm finding.
    v=u + at, therefore
    0 = 15*sin(theta) - 0.3t, therefore
    0.3t = 15*sin(theta)
    t = 15*sin(theta) / 0.3
    Now we multiply by 2 to find the time taken for the bullet to reach it's peak, then fall down again, and we get
    t = 30*sin(theta) / 0.3, and 30/0.3 = 100, so
    t = 100*sin(theta).

    OK, now to find how far the bullet will travel horizontally (s), we multiply t with the Xvel:
    s = 100*sin(theta)* 15 * cos(theta), so
    s = 1500.sin(theta).cos(theta)

    So I have 2 questions:
    1- Am I right so far?
    2- My AI will figure out how far away it needs to be shooting, so if I know s, how do I solve the above equation for theta?

    cheers,
    metal
    Last edited by metalmidget; Nov 9th, 2007 at 02:00 AM. Reason: Removing dead image

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Solving s = 750sin(theta).cos(theta)

    1) Looks like it. You could also use s=ut+0.5at2here.
    2) Remember that sin(2x) = 2 sinx cosx

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

    Thread Starter
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Solving s = 1500sin(theta).cos(theta)

    1- I didn't use s = ut + 1/2at^2 because then I would have had to use the quadratic formula and surds are icky.
    2- Wow I never knew that.
    So if sin(2x) = 2Sin(x).cos(x), then
    sin(2x)/2 = sin(x).cos(x), which substituting into my equation gives
    s = 1500.sin(2*theta)/2, which leaves me with
    s = 375.sin(2*theta), and from there I can solve it.
    So I did that right?
    cheers,
    metal

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Solving s = 1500sin(theta).cos(theta)

    Quote Originally Posted by metalmidget
    So I did that right?
    cheers,
    metal

    Except the dividing 1500 by 2 bit.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  5. #5

    Thread Starter
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Solving s = 1500sin(theta).cos(theta)

    lol, duh. woops.
    750 was the old figure I was using before I remembered I had to double my 't' value from the first stage. 750/2 = 375 which is where that came from

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width