|
-
Mar 7th, 2002, 03:02 PM
#1
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?
-
Mar 7th, 2002, 03:15 PM
#2
-
Mar 7th, 2002, 03:18 PM
#3
Lively Member
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)
-
Mar 7th, 2002, 04:10 PM
#4
Lively Member
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?
-
Mar 7th, 2002, 04:22 PM
#5
Good Ol' Platypus
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)
-
Mar 7th, 2002, 04:33 PM
#6
it works, thanks very much.
such complicated formulas, where do you come up with these things?
-
Mar 8th, 2002, 07:17 AM
#7
PowerPoster
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...
-
Mar 8th, 2002, 09:37 AM
#8
Addicted Member
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.
-
Mar 8th, 2002, 11:51 AM
#9
Retired VBF Adm1nistrator
You could use this function that I'm using in a game I wrote
VB Code:
'' What is the distance between two given set of co-ordinates ?
Private Function DistanceBetweenTwoPoints(point1 As CoOrd_type, point2 As CoOrd_type) As Single
DistanceBetweenTwoPoints = (((point2.X - point1.X) ^ 2) + ((point2.Y - point1.Y) ^ 2)) ^ 0.5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|