Results 1 to 5 of 5

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

Threaded View

  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

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