Results 1 to 15 of 15

Thread: collision error on game . why ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    15

    collision error on game . why ?

    i have that shooting game with angles and velocity and collision detectio in it too . but it seems that it has some problems in it.
    for example when i hit the target with an angle of 80 degrees and a power of 104, the bullet just goes through it and nothing happens ( but because i hit it something has to happen ! ) . but when i have the same angle ( 80 ) and now a power of 105, it its the target and detects collision and does the assigned event .
    what's wrong with this !! it seems so weird and crazy ! please see the program along with its code and notify me what and where the error is and how can i fix it .
    thank you very very much !

    i have the file zipped .
    Attached Files Attached Files

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    The problem with this code, is that it is moving to many pixels a time....so on it way down it's moving something like 40pixels a time. That means that it is possible for it to "jump over" the object you are shooting at....look at my picture to see the movement of your circle...

    So the only way to fix this things is to move the object less but update the movement faster
    You can do this in many ways. Probably isn't the timer control the best solution, but it's a nice start...

    Post again if you have more troubles...
    Attached Images Attached Images  

  3. #3
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Or you could draw a line from the first position to the second and si if that line colides with anything and if it doesn't you draw your ball at the new position.
    Just don't ask how to do it, 'cuz I don't know
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by McCain
    Or you could draw a line from the first position to the second and si if that line colides with anything and if it doesn't you draw your ball at the new position.
    Just don't ask how to do it, 'cuz I don't know
    If you had looked at his "game" you would see that that would be difficult...because his circle is not going in a straight line, so that would be more job then necessary...

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    And BTW you don't want a line on the screen every time anything moves in your game....and an other thing is that with a simple line you don't have the opportunity to check for left and "right" property...so it would be more difficult to check if it really did hit something...

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    15
    thanks for the nice explanation and the cool picture . i found out what my error is but i didn't exactly get how to fix it !! can you explain the fing part a bit more ( maybe a code )
    thankyou very much !

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    the fing part
    What fing????

  8. #8
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    OK...look at this example...it has no collision detection...but it's using the GetTickCount API to time the movement. And I have done so t (time) is updated with only 1/10sec every time, so it don't move that much every time, but it moves a lot more often...
    Attached Files Attached Files

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    15
    sorry , miss typing , i meant the fixxing part . i did not get it how to fix it !!! what property should i change .
    thank you

  10. #10
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by mikesmith6486
    sorry , miss typing , i meant the fixxing part . i did not get it how to fix it !!! what property should i change .
    thank you

    I thought that was what you meant so I did an example...download my last example from my last post and see if you can get it....

  11. #11

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    15
    thankyou
    but is there a simpler way.
    that was kind of complicated for a beginner .
    thanyou again

  12. #12
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    You can use your code too. in the update of t (time) set this line...

    VB Code:
    1. t = t + 0.1

    ...in your code it's probably t = t + 1...but then you would have to declare t as a double and not a long...

    ...if you do this the object will move much slower...so you would have to change the timer interval.

    BTW: The object might not move in the same path as before. But the path will have the same shape

  13. #13

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    15
    wooooooooooooo!!!!!!!!!!
    the program goes weird ?
    why?
    any suggestions?
    you mentioned the pixels in the earlier posts . you said it was something like 40 and they missed the shape . can i decrease the pixels some how ? in that case it has to work !!!
    thnakyou

  14. #14
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by mikesmith6486
    wooooooooooooo!!!!!!!!!!
    the program goes weird ?
    why?
    any suggestions?
    you mentioned the pixels in the earlier posts . you said it was something like 40 and they missed the shape . can i decrease the pixels some how ? in that case it has to work !!!
    thnakyou
    What do you mean by that your program foes weird???

    What I said about 40 (was just a fictive number) is that it doesn’t move like the sun on the sky. It moves a little bit, then it is drawn on the screen...then it is moved a little bit...then it is drawn to the screen.....So if you change the t (time) it will update it self more often or less often...by setting it to 0.1 (double) then every time it is drawn to the screen it has moved less then if time was 1....this is physics and you just have to understand the formula to get this...

  15. #15
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    And BTW you don't want a line on the screen every time anything moves in your game
    You wouldn't draw the line on the hDC for the window, just in memory... But as you said, it probably isn't a good solution anyways...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width