Results 1 to 14 of 14

Thread: Jump and Run Collision

  1. #1

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181

    Jump and Run Collision

    Hi Everoyone
    Well I made tilebased Jump and Run games, but I was never happy with the outcome.
    I have a slight problem with the collsion detection. I always used to have a tile either be walkthrough or not. Now I want things like diagonal pathes and stuff like that.
    So should I use masks for the tiles? Has anyone ever done a fast running program, that used masks for the collision detection?

    Than I would need some good code for collision detection anyways, because my code always was a little messy. If anyone has a good sample please tell me.
    Sanity is a full time job

    Puh das war harter Stoff!

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    At VoodooVB (http://voodoovb.thenexus.bc.ca/) there are a few tutorials that discuss the usage of fast rectangular, circular and vertex-based collision detection. I suggest you look into that.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I am having a look right now
    thanks
    Sanity is a full time job

    Puh das war harter Stoff!

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    I'd use rectangular collision for the tiles, and circular collision for the sprites.

    A good technique I saw in professional games that use rectangular collision for the tiles is that when the player collides with a wall only partially, he will be moved in that direction (the player will never be stuck in walls, instead he will slip):

    Code:
    The player collides with a wall, but only with his left side
    
    ---
      XX
    
    The game automatically moves him/her a bit to the right each frame, so he can pass :)
    
    ---
       XX
    This is a trick that players hardly notice (so most small games don't have this) and usually makes them happy with your game
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    In the moment I am only using rectangular collision and I have that move thing implemented. I would have no Idea how to work without it.
    Once the game get's little more interesting I will probably post it so you can see why I need to implement this.
    But I still don't know how to implement slopes if I use the rectangular.
    Sanity is a full time job

    Puh das war harter Stoff!

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Just use a big "If...ElseIf...ElseIf...End If" like I did

    Like this:

    VB Code:
    1. 'If there's a wall in the top-left corner of where the player is moving to, and there isn't in the top-right corner of where the player is moving to...
    2. If DetectCollision(NewPlayerX,NewPlayerY) = True And DetectCollision(NewPlayerX+PlayerWidth,NewPlayerY) = False Then
    3.   'Move a bit to the right. Also don't move up!
    4.   PlayerNewX = PlayerX + PlayerSpeed
    5.   PlayerNewY = PlayerY
    6. End If

    That's when the player presses the Up key and you set the NewPlayerX/Y with his new coords. You'll need to make the same thing if the top-right corner is blocked, for when both of the corners are blocked (the player can't move there), and when both of them are not blocked. You'll also have to repeat this for the other 4 directions.

    I know it's hard, but with some paper and a pen you'll get there
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    no I got all that long ago, but my problem is tiles that have slopes.
    somethig like this:

    _______
    \
    \______________/

    I need collision with the tiles that have different slopes!! I probably have to use masks.
    Sanity is a full time job

    Puh das war harter Stoff!

  8. #8
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Nope, masks is a bad idea - it's too slow and you can get the same results by using polygon collision detection
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  9. #9

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I kind of doubt that the polygon collision detection would be more efficient on tiles, than masking.
    Does Anyone know Jazz Jack Rabbit 2 I believe it uses masks.
    Sanity is a full time job

    Puh das war harter Stoff!

  10. #10
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Read the article, you'll be convinced after you do it

    You'll still have to use rectangular collision before looking at the mask's pixels, you're not gonna loop trough all of the pixels of the map every time you wanna detect a collision, are you?!
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  11. #11
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Ok... what I was trying to say is: before looping trough EVERY pixel in a mask to see if it's colliding with the player, you still have to perform a basic rectangular collision detection - otherwise you'd have to detect collision with ALL of the tiles in the map using masks, which is a very slow process! This way you can by-pass some of them if there isn't a rectangular collision

    Ah, forget about it, it's in the article on collision detection with masks
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  12. #12

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    Well yeah I will have a closer look into all of that.
    Thanks
    Sanity is a full time job

    Puh das war harter Stoff!

  13. #13
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You're welcome

    But if your game gets too slow, you know where the problem is
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  14. #14

    Thread Starter
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    Well I said I will take a look into all of that and decide for the fastest version of course.
    Sanity is a full time job

    Puh das war harter Stoff!

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