Results 1 to 9 of 9

Thread: Ranged Fire

  1. #1
    wehttam13
    Guest

    Angry Ranged Fire

    I am making a game that uses 50*50 pixels(rpg) where a character walks around(so far). He needs to be able to shoot at things, based on the range of his rifle. I have determined how to make a line travel from him to the enemy. But, I need to determine the range at what it is.

    i.e.
    if it travels up 4 x's, and 4 y squares, then the range should be 4.
    if it travles across 4 x's, and 0 y's, then the range is 4.
    if it travels up 3 x's, and 2 y's, then the range should be 3.

    anybody have any help?

  2. #2
    Lively Member jamieoboth's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    116
    Is the game 3D or flat?
    Is it top down, or 1st person?
    Is there more than one enemy at a time attacking? SOO MANY QUESTIONS UNANSWERED!
    Ich widerstehe allem - nur nicht der Versuchung

    (I can resist anything but temptation)

  3. #3
    Lively Member jamieoboth's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    116
    If it is 3D, you could put 4 lines to the center of the person/target. Then, the further away the target is, the smaller the gap between the 4 lines is. Measuring between them, you could work out how many times the results need to be times by. (I think). It seems OK in my mind, but I am a loony...
    Ich widerstehe allem - nur nicht der Versuchung

    (I can resist anything but temptation)

  4. #4
    Lively Member
    Join Date
    Jan 2002
    Location
    USA all the way!
    Posts
    82
    Have you tried using formulas to determine the range?

    Range=sqrt((x1-x2)^2+(y1-y2)^2)
    ex: if your guy was at 10,5 and the enemy was at 20,10 then the range would be about 11.

    This is basically the pythagorean theorem, just rearanged a bit.
    Often talked of, never seen,
    Ever coming, never been,
    Daily looked for, never here,
    Still approaching, coming near,
    Thousands for its visit wait,
    But alas for their fate,
    Tho' they expect me to appear,
    They will never find me here.

    What's this about?

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Actually jamieoboth, he did answer the 2D/3D question. Number of enemies does not matter, and since it is a 2D RPG it is obviously top-down, or another viewpoint that won't change based on where the character is. He answered the 2D by specifying the number of pixels (50x50).

    I would suggest the pythagorean theorum as Killerguppy has suggested. A good bit of code, that!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    wehttam13
    Guest
    it works, thanks very much.

    such complicated formulas, where do you come up with these things?

  7. #7
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    School, believe it or not. Occaisionaly something we were taught comes in handy.

    Look up pythagoras to see how simple it really is...

    Most things in games can be made using really simple things (or combinations of simple things).
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  8. #8
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    if ya dont like/know math, then yer not gonna make it as a programmer ^^ ever hear someone complain during trig class "when are we ever gonna use this crap :p " ? well, here it is :) math is one of my fave classes.. its english and history that i'm still wonderin when i'm ever gonna use :]
    To understand recursion, one must first understand the concept of recursion.

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You could use this function that I'm using in a game I wrote

    VB Code:
    1. '' What is the distance between two given set of co-ordinates ?
    2. Private Function DistanceBetweenTwoPoints(point1 As CoOrd_type, point2 As CoOrd_type) As Single
    3.     DistanceBetweenTwoPoints = (((point2.X - point1.X) ^ 2) + ((point2.Y - point1.Y) ^ 2)) ^ 0.5
    4. End Function

    CoOrd_type is a UDT that just as a .x and a .y member
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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