|
Post by scotthuggins on Mar 18, 2015 19:39:56 GMT -5
Christopher- I noticed you mentioned you are coding a game and in doing so are attempting to do so without using the BIOS routines. I totally get why you are doing that. I have collision detection working well in my game but the # of cycles it uses is slightly astonishing! I want to try and figure out an alternative. I don't think merely checking a vector (say a player's Y,X position ship) and comparing to a wall's Y,X position (for example) will do it. What if a wall is a diagonal line? I am wracking my brain to try and figure out something else. See below, maybe this explains what I am asking.. If I have a part of my playfield with this diagonal line: * * * * How can I (if even possible) detect the player's ship when it comes into contact? Again, the BIOS routine I am using ( $f8ff, otherwise known as Obj_Hit) is working - but really kind of taxing. Thanks for any ideas from anyone! Scott
|
|
|
Post by christophertumber on Mar 19, 2015 10:21:15 GMT -5
What you're doing is trying to determine if a point is on a line. Depending on how much you need to abstract this you have a variety of approaches. If you can create an equation for the line of the form y=mx+b (turns out, you will need that high school math after all ) Then just take either the x or y (depending on how you wind up formatting the equation) and solve for the other ordinal. If you wind up with the original (x,y) then the point is on the line. If not, it isn't. If you can't do this (ie; you potentially have hundreds of different lines you need to check) then given two points that are on the line (you must have this information since you are drawing the line) you need to determine the equation. More high school math: www.mathsisfun.com/algebra/line-equation-2points.htmlAlternately, if you don't have too many lines you could use a look-up table and do point to point comparisons (though you want to optimize the number of compares so you don't wind up with a heavier solution than finding point on a line) One thing to keep in mind here is that you doing collision detection with the line only. So if it's possible for something to move >1 "pixel" then your collision detection will fail. One suggestion would be to asra everything to divide by 2.
|
|
|
Post by kokovec on Mar 19, 2015 19:09:41 GMT -5
LERP
|
|
|
Post by scotthuggins on Mar 19, 2015 19:38:30 GMT -5
>y=mx+b (turns out, you will need that high school math after all ) Thanks, Christopher.... time to use the analytical geometry I never thought that I would need to use! :-) >LERP Thanks.....I think.
|
|
|
Post by christophertumber on Mar 19, 2015 21:28:20 GMT -5
|
|
|
Post by gorf68 on Mar 28, 2015 14:37:40 GMT -5
I mostly always use customised hit routeans, as the BIOS ones aren't really suited for anything I've tried to do so far.
I've started work on a small game where all collision detection is handled via drawing coordinate.
|
|
|
Post by vectrexrc2 on Mar 29, 2015 18:51:11 GMT -5
there are collision examples here pelikonepeijoonit.net/files/vec/coders.html"This is a little snippet of code Alex posted in the newsgroup (hope you don't mind me posting it here as well). It demonstrates how you can use a circular 'shield' around objects for collision detection instead of rectangles." "More help to the beginning Vec programmer (I hope). A detailed example on collision detection (and joystick reading).. This is a fixed version (v2) that now works with different sized objects, thanks to Alex H. for pointing that out!"
|
|