How do you check for object collisions?
Author |
Message |
Poutine King
|
Posted: Tue Apr 20, 2004 10:16 am Post subject: How do you check for object collisions? |
|
|
As the topic asks, how do you check for object collisions? I tired this:
(the x, y, x2, y2 are the positions of two circles)
if x =x2 and y=y2 then
x:= 0
y:= 0
x2:=100
y2:=100
end if
the ":=0" or ":=100" is so that they go in a prison but the first circle goes there right off the bat.
How do you check for two objects colliding??? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Tue Apr 20, 2004 11:20 am Post subject: (No subject) |
|
|
[url=http://www.compsci.ca/v2/viewtopic.php?t=3525]
Checking for Collision Detection. By DanShadow.
[/url]
That is how. |
|
|
|
|
![](images/spacer.gif) |
gamer
|
Posted: Tue Apr 20, 2004 6:10 pm Post subject: (No subject) |
|
|
thnx...good link |
|
|
|
|
![](images/spacer.gif) |
Poutine King
|
Posted: Thu Apr 22, 2004 10:09 am Post subject: (No subject) |
|
|
Uhh, what about characters?? I can make boundries and walls work but how does it work with another moving odject? |
|
|
|
|
![](images/spacer.gif) |
Paul
![](http://i12.photobucket.com/albums/a207/paulbian/DDRDuck.png)
|
Posted: Fri Apr 23, 2004 8:55 pm Post subject: (No subject) |
|
|
you could use whatdotcolor and check for the edge of one object, or u could just use coordinates and compare the 2 different positions. |
|
|
|
|
![](images/spacer.gif) |
Poutine King
|
Posted: Thu Apr 29, 2004 10:23 am Post subject: (No subject) |
|
|
Actually the walls don't work??? Oi! They should, I used whatdotcolor to check if the co-ordinates of the character met those of the walls. But it doesn't work on the corners??? Can you guys give me an example so I can see what you mean. I'm a visual learner ya know. |
|
|
|
|
![](images/spacer.gif) |
Paul
![](http://i12.photobucket.com/albums/a207/paulbian/DDRDuck.png)
|
Posted: Thu Apr 29, 2004 3:22 pm Post subject: (No subject) |
|
|
huh? Idk if this helps u, its just a ball u can move with ur arrow keys, and whatdotcolor collision on the corners work... is this what u mean?
code: |
setscreen ("offscreenonly")
var x, y : int
x := 100
y := 100
var chars : array char of boolean
loop
drawfillbox (0, 0, maxx, maxy, black)
drawfillbox (10, 10, maxx - 10, maxy - 10, 0)
drawfillbox (maxx div 2, maxy div 2, maxx div 2 +150, maxy div 2 +50, black)
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
if whatdotcolor (x, y + 13) = 0
then
y := y + 5
end if
end if
if chars (KEY_RIGHT_ARROW) then
if whatdotcolor (x + 13 , y) = 0 then
x := x + 5
end if
end if
if chars (KEY_LEFT_ARROW) then
if whatdotcolor (x - 13, y) = 0 then
x := x - 5
end if
end if
if chars (KEY_DOWN_ARROW) then
if whatdotcolor (x, y - 13) = 0 then
y := y - 5
end if
end if
drawfilloval (x, y, 10, 10, 12)
View.Update
delay (10)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Poutine King
|
Posted: Fri Apr 30, 2004 8:17 am Post subject: (No subject) |
|
|
YES! Thank you so much, now it works! Bless your soul sonny. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|