
-----------------------------------
Axarent
Fri Jun 06, 2003 6:03 pm

Having collision problems and [why laws of universe r wrong]
-----------------------------------
I'm a newb to programming and was wondering if anyone could give me suggestions on how to do collisions for hitting a target that you've shot at.  I've been trying and just can't get it to work.  Thx

-----------------------------------
Tony
Fri Jun 06, 2003 7:04 pm


-----------------------------------
we got tutorials on rectangle and circle colision detections available... all depends on what kind of target you're trying to hit and with what.

-----------------------------------
Axarent
Fri Jun 06, 2003 9:46 pm


-----------------------------------
well I was trying a space shooter with a moving enemy picture that I drew in paint and flys across the screen.  i'm using draw line to create the shot should I try to use draw oval and box to make the enemy to make it easier??

-----------------------------------
Tony
Fri Jun 06, 2003 9:58 pm


-----------------------------------
well you could treat the ships as circles (keep the picture though) and use equations y = mx + b and x^2 + y^2 = radius to see if your lazer line intersects the ship or not.

-----------------------------------
Axarent
Sun Jun 08, 2003 5:47 pm


-----------------------------------
so would I use the coordinates of my laser line for y and x in y=mx +b and the coordinates of the enemy for x and y in x^2 + y^2 = radius and then check if the line intersects the diameter at anytime right??

-----------------------------------
Tony
Sun Jun 08, 2003 8:57 pm


-----------------------------------
yeah, but as bugz pointed out in another post, I got forumulas mixed up a bit...

for the line, its better to use Ax+By+C=0 I think...

circle is (x-a)^2 + (y-b)^2 = radius^2 where a/b are x/y of circle's center.

-----------------------------------
PaddyLong
Sun Jun 08, 2003 10:20 pm


-----------------------------------
radius^2 you mean for the circle :P

-----------------------------------
Andy
Sun Jun 08, 2003 10:26 pm


-----------------------------------
uhoh tony, forgetting rade 10 math eh?

-----------------------------------
Martin
Sun Jun 08, 2003 10:40 pm


-----------------------------------
And rade 9 english, dodge ;)

-----------------------------------
Tony
Sun Jun 08, 2003 10:50 pm


-----------------------------------
huh? it says = radius ^2

did anyone else read 1984? Great book  :twisted:

-----------------------------------
Andy
Mon Jun 09, 2003 8:01 am


-----------------------------------
riiite that's y it says last edited by tony... ya its an awsome book, big brother's watching u...

-----------------------------------
Grey_Wolf
Mon Jun 09, 2003 3:48 pm


-----------------------------------
1984 is a great book. What does that have to do with anything.

-----------------------------------
PaddyLong
Mon Jun 09, 2003 4:35 pm


-----------------------------------
1 + 1 is only 2 becuase we've been trained to believe it  (or somethign to that effect... haven't read the book for a while)

-----------------------------------
Andy
Mon Jun 09, 2003 5:22 pm


-----------------------------------
hey man, tony owns the site, he can say any thing he wants..  :wink:

-----------------------------------
Tony
Mon Jun 09, 2003 6:05 pm


-----------------------------------
it was 2+2=5... and those guys are right... here's the math proof behind it (someone had part of this equation as their signature)

assume x = a
x^2 = ax
x^2 - a^2 = ax - a^2
(x+a)(x-a) = a(x-a)
x+a = a
x + x = x
2x = x
2x + x = x + x
3x = 2x
5x - 2x = 2x
5x = 2x + 2x
*divide both sides by x
5 = 2 + 2

So teachnically... the book is telling the truth. 2+2 does equal to 5.

-----------------------------------
Catalyst
Mon Jun 09, 2003 6:10 pm


-----------------------------------
that is so wrong

-----------------------------------
Axarent
Mon Jun 09, 2003 6:34 pm


-----------------------------------
Wow now I can tell people that 2+2 does = 5.  Anyways I'm using mine as a function and I'm having difficulty getting it to work so would it be easier to just make it an if in the code somewhere else?  and cause it's a fcn I've put a for loop so it can get true or false multiple times, is that good?  Well here's what I've got for the collision function

var x : int := 150
var y : int := 25
var x1 : int := x + 25
var y1 : int := y + 25
var y2: int := maxy
var x2 : int := 150
var centrex, centrex1, centrey, centrey1 : real

function enemydead : boolean
    centrex := x1 - 7.5
    centrex1 := x2 - 19
    centrey := y1 - 7.5
    centrey1 := y2 - 19
    var enemyradius : real := ((centrex1) * (centrex1) + (centrey1) * (centrey1)) ** 0.5
    var shotradius : real := ((centrex) * (centrex) + (centrey) * (centrey)) ** 0.5
    var distance : real := ((centrex1 - centrex) * (centrex1 - centrex) + (centrey1-centrey) * (centrey1-centrey))**0.5
    for i : 1 .. 21
        if distance < shotradius + enemyradius then
            result true
        end if
    end for
    result false
end enemydead

-----------------------------------
Andy
Mon Jun 09, 2003 7:22 pm


-----------------------------------
u morons, he divided by 0!!!
when he divided (x-a) on both sides, he divided 0

-----------------------------------
Tony
Mon Jun 09, 2003 8:07 pm


-----------------------------------
eh... the function will end once it returns a value :?

dodge -> When you divide by 0, everything is possible  :lol:

BTW, read line

X^2 - A^2 = AX - A^2

if you replace A with X (since they equal to each other) you'll get 0 = 0

thats the reason A is in equation, so that people dont notice it.

And easy on the words there...

-----------------------------------
Axarent
Tue Jun 10, 2003 2:41 pm


-----------------------------------
Would it be easier as a procedure of process?  or what's the best possible way I can do this???

-----------------------------------
Tony
Tue Jun 10, 2003 2:56 pm


-----------------------------------
processes are bad, end of story... so I guess you're better off with a procedure  8)

-----------------------------------
octopi
Tue Jun 10, 2003 4:52 pm


-----------------------------------
Using what tony wrote you could also say that

3 == 2


x^2 = ax 
x^2 - a^2 = ax - a^2 
(x+a)(x-a) = a(x-a) 
x+a = a 
x + x = x 
2x = x                   //