Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d diagonal collisions

Author
Message
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 27th Sep 2010 21:10
I can use "box type" sprites as walls so that a check for 2d wall collisions can be made, but what if a wall is diagonal?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 27th Sep 2010 23:42
It seems to me that the sprite "bounding box" for collisions stays a square that is sized to encompass all of the sprites pixels, illustrated here:



So, you'll have to come up with some other process to detect a collision with a diagonal wall.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 28th Sep 2010 08:21
well... a general case solution for collision like this isn't really a thing for the newcomers board. I like to use 2d vector math. Here's a demo I came up with:


from this thread:
http://forum.thegamecreators.com/?m=forum_view&t=174030&b=1

but uh... for the most part there isn't a nice "if xpos<0 then xpos=0" one line statement.

45 degree angles might be easier.

Basically, in the code i posted, the main work is being done in the function linColl()

If the circle is colliding with a line, then linColl() makes sure the circle's distance from the line is the radius. If the circle is colliding with the endpoints of a line, then linColl() makes sure the circle's distance from the endpoint is its radius.

jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 3rd Oct 2010 14:06 Edited at: 3rd Oct 2010 14:07
Think code snippet or something similar may be a way of dealing with diagonal lines?
The dreaded point command is only used after a normal collision. Any improved coding would be welcomed.ink rgb(255,0,0),0
box 0,0,5,5
get image 2,0,0,5,5

repeat
cls 0
gosub diagonal_wall
sprite 2,mousex(),mousey(),2

if sprite collision (2,3)
if rgbb(point(mousex(),mousey()))=255
ink rgb(255,255,255),0
box 410,70,540,90
get image 1,410,70,540,90,1
sprite 1,410,70,1: rem switch the white box on if diagonal found
hide sprite 1
endif
endif
until spacekey()=1
end

diagonal_wall:
ink rgb(0,0,255),0
for t=0 to 3
line 200,t+200,450,t+350
next t
get image 3,200,200,450,453
sprite 3,200,200,3
return

Sorry, don't know how to use code snippets....

Login to post a reply

Server time is: 2024-09-28 22:37:49
Your offset time is: 2024-09-28 22:37:49