Results 1 to 9 of 9

Thread: calculating angles

  1. #1
    Guest

    Post

    i am making a "tank" game and i need help making the "bullet" fired from the tank go at a angle and power that has been entered by the player. i dont want it going in a straight line i want it to go up then back down, but i cant figuer how to do that.

    any help would be greatly apreciated. thank you

  2. #2
    Guest

    Post

    i think i have to use the parabola formula but i forgot the formula. it was something like this but it wont work for me.

    sub command1_click()
    form1.scale (0,500)-(1000,-500)
    for x = 0 to 1000
    pset (x , sin(x ^ 2)
    next x
    end sub

    i thought that is how you draw a parabola but it didn't work for me. any help would be greatly apreciated.

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I haven't used Newtonian Mechanics for a few years, but I think these are the equations you are looking for, you'll need to tweak all the variables to get them the way you want them..

    In a Form with a Large Picturebox, 2 Textboxes and a Command Button..
    Code:
    Private Sub Command1_Click()
        Dim pX As Single    'X Dist
        Dim pY As Single    'Y Dist
        Dim pT As Single    'Time
        Dim pUy As Single   'Initial Y Velocity
        Dim pUx As Single   'Initial X Velocity
        Dim pG As Single    'Gravity
        Dim pW As Single    'Wind Resistance
        Dim pV As Single    'Velocity
        Dim lX As Single
        Dim lY As Single
        
        pW = 0      'Wind Resistence
        pG = -8.13  'Gravity
        pV = Val(txtSpeed) / 5  'Get Entered Speed
        'Calculate X & Y Initial Velocity
        pUy = Round(Sin(Val(txtAngle) * (3.14 / 180)), 2) * pV
        pUx = Round(Cos(Val(txtAngle) * (3.14 / 180)), 2) * pV
        Picture1.AutoRedraw = True
        Do
            pT = pT + 0.01 'Increment Time
            pY = pY + (pUy * pT) + ((pG * (pT ^ 2)) / 2) 'Distance along the Y Axis
            pX = pX + (pUx * pT) + ((pW * (pT ^ 2)) / 2) 'Distance along the X Axis
            Picture1.PSet (lX, Picture1.ScaleHeight - lY), Picture1.BackColor
            Picture1.PSet (pX, Picture1.ScaleHeight - pY), vbBlack
            lX = pX
            lY = pY
            DoEvents
        Loop While pY > 0 And pX < Picture1.ScaleWidth 
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  4. #4
    Guest

    Post

    ALL i can say is :
    DAAAAAAMMMMMMMMMMMMEEEEEEEEEEEEE !!!!

    Dude where did you get that info my god ...
    Is there a way of learning this things ?

  5. #5
    Guest

    Post

    aaron your the man! i have been slacking off in math too much =).

    thanx buddy

  6. #6
    Guest

    Post

    aaron if you could, can you please explain how the code works? i dont understand why you need time and some other things to calculate distance and angle. i would be so greatfull if you can explain how it works.

    also the variable pV doesn't work because it is a code word so i changed it to something else, so it works fine. and how do i make the pset command start from my "tank" which is actually an image box? because the code works fine but it doesn't shoot from my tank =).

    thanx again, i really owe you one.

  7. #7
    Guest

    Post

    well i understand the code now so you dont have to explain. i also got it to fire from my tank and not the corner of the picturebox.

    but one more thing, how do i make the trail keep going untill it hits land? my land isn't a flat surface, it has been drawn using the sin command. so i dont want the trail stopping when y is less then 0 i want to it keep going untill it hits ground.

    if you want i can send my source to you if it will make it easier for you. thank you so much

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The easiest way would be to check the Pixel Color at the "Bullets" Coords using the Point Method, if it's a Certain Color, (The Color of the Ground), it's Landed.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  9. #9
    Guest

    Post

    thanx aaron, again you figuered out how to solve someones problem. what would us peons ever do without you?

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