Box Collision Is Sticking
Author |
Message |
Prince Pwn
|
Posted: Sun Jan 28, 2007 12:23 pm Post subject: Box Collision Is Sticking |
|
|
How could I fix this? Here is my collision detection:
Turing: |
if a ('d') and x1 + rad1 > x2 and y1 > y2 - rad2 and y1 < y2 + rad2 then
x1 -= speed
elsif a ('a') and x1 < x2 + rad2 and y1 >= y2 - rad2 and y1 < y2 + rad2 then
x1 += speed
end if
if a ('w') and y1 + rad1 > y2 and x1 + rad1 > x2 and x1 < x2 + rad2 then
y1 -= speed
elsif a ('s') and y1 < y2 + rad2 and x1 + rad1 > x2 and x1 < x2 + rad2 then
y1 += speed
end if
|
Here's how I draw my boxes, and I move it with a-s-w-d:
Turing: |
Draw.FillBox (x2, y2, x2 + rad2, y2 + rad2, col2 )
Draw.Box (x2, y2, x2 + rad2, y2 + rad2, black)
Draw.FillBox (x1, y1, x1 + rad1, y1 + rad1, col1 )
Draw.Box (x1, y1, x1 + rad1, y1 + rad1, black)
|
Now if I'm against the other box, it sometimes sticks to it.
eg: If I press 'd' and go right against the second box, I can't go back left with 'a', but I have to go up or down with 'w' or 's' because it gets stuck.
EDIT: Same happens with up or down.
Actually I just realized my collision sucks, I'll re-write it. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
CodeMonkey2000
|
Posted: Sun Jan 28, 2007 12:47 pm Post subject: Re: Box Collision Is Sticking |
|
|
I think it is because you are missing a coordinate. Try: code: | if a ('d') and x1 < x2 and x1 + rad1 > x2 and y1 > y2 - rad2 and y1 < y2 + rad2 then
x1 -= speed
elsif a ('a') and x1 < x2 + rad2 and x1 + rad1 > x2 and y1 >= y2 - rad2 and y1 < y2 + rad2 then
x1 += speed
end if
if a ('w') and y1 + rad1 > y2 and y1 < y2 + rad2 and x1 + rad1 > x2 and x1 < x2 + rad2 then
y1 -= speed
elsif a ('s') and y1 + rad1 > y2 and y1 < y2 + rad2 and x1 + rad1 > x2 and x1 < x2 + rad2 then
y1 += speed
end if
|
|
|
|
|
|
|
Prince Pwn
|
Posted: Sun Jan 28, 2007 12:53 pm Post subject: Re: Box Collision Is Sticking |
|
|
Ah thanks so much. I'm practicing networking with Turing now that I got a crap computer from the school by moving boxes and having them collide |
|
|
|
|
|
|
|