Search code examples
c#visual-studio-2010collision-detection

Visual C#- Game Character gets all "jumpy" when checking for collision


I'm making my first game! It's a very simple 2D game, just a character that can run around and jump on blocks.

My timer's interval is 1, each tick it checks for a collision between the player and the blocks. For some reason the only block that the character doesn't get "jumpy" on is the last block that it's collision is checked. Maybe Multi-Threading will work?

This is my first game so sorry if the code is messy. I'll divide my code to two (Using pastebin because it's long, well at least for me):

  1. The whole game code: http://pastebin.com/GX4PtUuL

  2. What I think is needed: http://pastebin.com/GEBEinm8

If you need me to tell you more feel free to ask. Please remember that I'm not a 'high level' programmer, so I will not understand everything.

Thanks in advance!


Solution

  • OK, I have now looked at your code.

    It seems to be basically OK; especially collision checking in the Tick event is correct since you are using a gravitational force that works in time.

    It works OK, but only if the timer speed is slow enough, I found around 100ms to work fine..

    Here is tip that should help you further: The pixels, locations etc are all integers but player position and speed/force really should be stored and calculated as floats so you can fine tune things, especially the speed.