Results 1 to 14 of 14

Thread: Angles

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    In my hockey game, shooting the puck is becoming a problem. How do I make t always shoot at the net?

  2. #2
    Guest
    find the differences between the coordinates and use trigonometry to give you a heading to the net. you shouldnt need Tan(), just Sin() or Cos().

    Can't help much more without seeing your program.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I know of the functions, but I don't know trig yet

  4. #4
    Guest
    ok, gimme some numbers to play with and i'll try to work something our for you

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    the net is always here:
    Net.x = 120
    Net.y = 0

    the player is all over
    the screen is about 270
    the height is about 300

  6. #6
    Guest
    bear with me, i'm talkin to someone knowledgeable in this kinda thing.

  7. #7
    Guest
    OK here goes, the following is not VB code, so you'll have to decypher it, (should be easy)...

    Bearing = arcsin[ |x| / sqrt(x+y)] + 90(x>=0)(y<=0) + 180(x<=0)(y<=0) + 270(x<=0)(y>=0)

    |x| means absolute value of x
    sqrt means square root
    (y<=0) etc. are logical operators.


    x,y are the differences in positions.


  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    am I too late to join this discussion? Maybe you would like to work with vectors instead?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Whatever would be easier, wossname's or kedaman if you think vectors are easier than please post

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Vectors are of course easier, they save a lot of time, both in programming and runtime trigs just consume a lot, hehe-.

    Currently do you have a angle/speed set up? Or do you have anything else like vectors for the movement
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Anyway i'm introducing you to vectors! Because that's exactly what you need The speed is composed by x and y components so addition goes with no trigs at all, that means a lot of speed gain when calculating new position for each each sequence. To handle the coordinates you use an UDT, for instance here's Coordinate32:
    Code:
    Type Coordinate32
        x As Single
        y As Single
    End Type
    
    Function Scalar32ProjG2Vector(Target As Coordinate32, source As Coordinate32, Velocity As Single) As Coordinate32
    Dim k As Single
        k = speed / ((Target.y - source.y) ^ 2 + (Target.x - source.x) ^ 2) ^ 0.5
        With Scalar32ProjG2Vector
            .x = k * (Target.x - source.x)
            .y = k * (Target.y - source.y)
        End With
    End Function
    Function Vector32Add(V1 As Coordinate32, V2 As Coordinate32) As Coordinate32
        With Vector32Add
            .x = V1.x + V2.x
            .y = V1.y + V2.y
        End With
    End Function
    Now the two functions i pasted here, the first one should project the result speed vector of target and source coordinates, whereas you set the target to the net and keep the source as the puck. VectorAdd should be just fine for moving the puck, just set the puck coordinate to what you return by adding the puck to the speed.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Kedaman, you like physics don't you? One of my favorite classes back in college (until we got into E&M and ticked off the prof).
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    hey Kaverin (friend)

    I love physics and math, especially in combination with VB
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Guest
    If you ever need help with Particle/Wave Duality problems, then I'm your guy!

    I got 97% in that module in college, but i still got a "D" overall, go figure!

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