Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Box Collision Is Sticking
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince Pwn




PostPosted: 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
Sponsor
sponsor
CodeMonkey2000




PostPosted: 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




PostPosted: 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 Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: