Alternative Collision
BlitzPlus Forums/BlitzPlus Programming/Alternative Collision
| ||
I'm think there is an alternative way to do collisions. For collisions, I usually use the "If ImagesCollide" or "If ImageRectCollide" commands, but I think that there's another way to do collisions that involves some type of mathematical formula (I saw it in the "Programming for Teens" book but I don't remember it - and I don't have the book). But, I would like practice at one like that one so that if I decide to learn another programming language I'll know how to do it in that language too. Thus, can someone tell me what it is? Thanks. |
| ||
You could calculate the distance between objects and if that is less then their combined collision radius then you would have a collision. |
| ||
I've answered your post in the blitz3d forums. Do you really need to post the same question in multiple sections of the blitz forums - it puts me off (and perhaps others) answering when they go to the effort of answering in one thread only to find that you've asked it elsewhere as well... |
| ||
I'm sorry Matty. Sometimes the 3d forums tends to be more active. Thus, it is why I posted my question there too (I probably should have simply posted a link to this page when I posted the question in the 3d forum so they can simply answer my question here (or so). I got your response there. Thanks. Also, thanks Moore. I'll try that. When I get it, I may be using that collision method from now on. Last edited 2011 |
| ||
Moore, I'm interested in the code you wrote. Can you write that into my game program below and make it so that the "PLAYER" character can collide with the "DOOR." I tried to use the code that you wrote, but I failed. Thus, I'd like to see an example of it being used in what I wrote below so I can use it from then on. Thanks.Graphics 1640, 1000 PLAYER = LoadImage ("Ball.png") DOOR = LoadImage ("Door.png") Type PLAYER Field x,y End Type Type DOOR Field x,y End Type p.PLAYER = New PLAYER p\x = 500 p\y = 250 d.DOOR = New DOOR d\x = 500 d\y = 250 While Not KeyDown(1) Cls ;-------------------------Alternative Collision code----------------------- ; would like to see the alternative collision code being used ;here with the two characters loaded above (e.g. the PLAYER ;and DOOR characters) so that I can follow how they're used. Thanks. ;------------------------------------------------------------------------------------------- If KeyDown(208) p\y = p\y + 3 EndIf If KeyDown(200) p\y = p\y - 3 EndIf If KeyDown(205) p\x = p\x + 3 EndIf If KeyDown(203) p\x = p\x - 3 EndIf DrawImage (DOOR,d\x,d\y) DrawImage (PLAYER,p\x,p\y) Flip Wend Last edited 2011 Last edited 2011 |