More pointers

Discussion in 'Scripting & Programming' started by zxspectrum, Mar 1, 2007.

  1. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    As people know im doing stuff with visual basic. At the moment im on a project called pomndworld. I will give you a brief run down of what this is as that will make my question make more sense , i think.

    Basically pondworld will be a nice litle haven for frogs to lay about and do pretty much as they like, but with the danger of being eaten by a monster, which is in the shape of a gollum.

    Now say i have 2 frogs on the pond and i want tthe gollum to go for the nearest frog, how would i go about this. As the frogs locations become 3D like etc. Ive heard that i should be using parameters for this whicch is my reading for the weekend etc.

    I was wondering if anyone would be willing to help me in this but not by giving me the answers but just general guideance??

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    i suppose you could use the location method on each of the frogs and compare it to the location of the gollum. You would need to build a mathematical forumula using pythagoras to work out distances.

    so for instance:

    if frog a's location is (3, 5), Frog B's is (7, 6) and Gollum is (5,5) you would do this

    For Frog A)
    Horizontal = (5 -3) 2
    Vertical = (5 - 5) = 0
    Since they are on the same level, the distance is 2.

    For Frog B)
    Horizontal = (5 - 7) = -2
    Vertical = (5-6) = -1
    Distance = Square root of((-2 squared) + (-1 squared)) =
    Square root of (4 + 1) = 2.236

    So Frog A is closer and therefor your target.

    Bet you never thought you'd end up using pythagoras outside of school, eh?
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  3. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Your right, thats some more reading for me, i barely remeber pythagaros, i can just about remeber algebra lol

    Cheers for that fergal

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  4. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    And you can extend this to 3D. (Called the 'least squares' method usualy - even though that term really implies something more complicated)

    As an optimization you don't need to do the square root at the end - the ordering will be the same.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  5. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Where would i find anything on that Harry ??

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  6. Kraven

    Kraven Kilobyte Poster

    297
    3
    49
    I could of proberly helped a few years ago when I was at college and using Visual Basic alot. But I basically forgot everything I knew as I havent used it for a long while.

    I also made quite a good fighting game where your opponent would move towards your player, similar to how you want your game to work.

    Kraven
     
    Certifications: Network+, MCSA, 70-680
    WIP: A+, 70-685
  7. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    I dont suppose you would have a copy of that game would you Kraven, i wont copy i just want to loom how your code is constructed etc. if thats ok

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    This is a good start...

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Note that writing games often demands some fairly abstruse mathematical knowledge. Things like vectors, projections and suchlike.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  10. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    thanks Harry got a load of stuff there

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  11. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Spot on! I was about to mention vectors. The benefit with vectors is that they offer a lot more mathematical flexibilty over Pythagoras. Pythagoras, although mathematically less intensive, can grow into a massive and quite unmanageable mess for more complex problems, in addition to there being problems if both frogs are perfectly aligned. So, you want to find the nearest frog to the monster. Given that you have specified that the monster will only be hunting the frogs in the pond (forgive my assumption), you can treat it as a 2D space, because:

    1. You can assume that the monster and the frogs are floating - that is, they are on a level plane.

    2. Because you are working with a plane, the third dimension will always be zero.

    How do we approach this problem with vectors? You have asked that you only receive guidance, so here goes: What you need to do is find the magnitude (or length) of the vector with the monster representing the perceived origin (or tail of the vector) and each frog representing the head of the vector. Once you solve this you can easily work out which is the nearest frog in any direction, be it behind, front or to the side of the monster.

    HTH.
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  12. Kraven

    Kraven Kilobyte Poster

    297
    3
    49
    I'm afraid not mate, I deleted all my college work ages ago.

    Kraven
     
    Certifications: Network+, MCSA, 70-680
    WIP: A+, 70-685

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.