collision question
BlitzMax Forums/BlitzMax Beginners Area/collision question
| ||
can I check for a collision between a drawnline using drawline and an image? |
| ||
no Rect (-> area) or Image only |
| ||
so how would I create a laser weapon then? |
| ||
Pure guess here... You have your start point (e.g. shipx, shipy) You know your target point (perhaps mousex(),mousey()) Use atan2 to get the angle and work out how to 'setrotate' to point to that target. Then use drawimagerect with that rotation. It might then be possible to check the rotated, drawimagerect'ed image with your other images. No idea whether it'll work though. |
| ||
ok ill try it, ill let you know when i leave work. |
| ||
I never done that either but wouldn't it be easy to just create a lazer light image and then use collideimage to check for collition? |
| ||
drawimagerect needs an image supplied, isn't like drawrect. |
| ||
Yes, that's right. |
| ||
well what Im doing now, is i did a line about 300pixels long, random the colours its drawn with along the orange scale, to make it an orange laser. and setting the handle of the image to be the bottom, so the line is drawn from the bottom when i fire, and the top of course is 300 pixels ahead. so voila, laser type weapon, but the collision is awry this way :). |
| ||
Read each pixel in the path of the laser, and stop when the pixel is different to the normal back colour. Then at the pixel before the change you know that you are about to hit something http://www.blitzbasic.com/Community/posts.php?topic=49893#558158 (ReadPixel link) |
| ||
... or create a small segment of the orange (or, better, greyscale) laser as an image. |
| ||
Or just go through all pixels and do a colliderect with a 1x1 rect (ie the pixel of the line) and look if this one collides. This can be done x steps in front or back, as you like and need it and due to 1x1 it is very fast Reading each pixel is no solution in BM at the moment as all solutions so far grab something. |
| ||
Edit. Mistake sorry |
| ||
thanks guys? HK you sorry means mistake in advice? dreamora, what you said sounds, good but a little confusing. tonyg, ill try that. but if i make it so that the part nearest the ship when firing is grey wont it look like not appearing to be fired from the ship. i will post a screenshot of me firing several laser beams when I get home. @ work now. |
| ||
HK you sorry means mistake in advice? If the mistake was in the advice I would have edited the advice. The sorry was because I critised Dream, then realised that is was me not understanding, I had thought he was just paraphrasing my advice, then when I read it again I realised what he ment |
| ||
here is the screen shot![]() looks better in the game... when its running, not as horrible as it looks there. for the collision code, i set the handle back to 0.0 so when the beginning of the laser touches the target it should disappear. but funny thing, the laser just becomes really fady before disappearing, when it collides with its target. |
| ||
tonyg, ill try that. but if i make it so that the part nearest the ship when firing is grey wont it look like not appearing to be fired from the ship. not sure what you mean but have the image greyscale and use setcolor to make it orange, blue, red whatever. |