Results 1 to 9 of 9
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Java platformer, rect collision

    Hi, basically I've made a platformer, you can walk around and jump, but I can't make the proper wall collision...
    I mean, there is a floor, and a block (rect) on the top of it, left side of the wall is working but right one not...
    Basically how do I do a normal collision? Any tips?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  2. #2
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: Java platformer, rect collision

    basically if it's rectangles, there's a nice method in the rectangle api, called intersects.

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: Java platformer, rect collision

    Yeah I am using that right now, but I think wrongly xD
    When I press the left button and there is a rect on my way and if I touch it, I stop moving same for the right but that makes me stuck in the rect...
    I am not sure what to do..
    Basically I've made character's position change a little farther from the block so he won't be stuck in it, but that makes it weird...
    WARNING I am Russian so it's possible that I wont understand you correctly...

  4. #4
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: Java platformer, rect collision

    maybe check for collision before actually moving the character, i did it in my move method, whenever the character moves, i check for collision
    and only if there's no collision it moves.

  5. #5
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: Java platformer, rect collision

    But I did before:
    <if not colliding then move character>
    and another thing that it moves like 3 pixels each frame (the game repaints everything every like 100 milliseconds)
    and the character may get through the wall and then it just stuck there...
    WARNING I am Russian so it's possible that I wont understand you correctly...

  6. #6
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: Java platformer, rect collision

    well it does depends on the actual implementation of the "world" you made, but for me, i did a check of the sort -
    Java Code:
    for (int i = 0;i>dx;i++)
    {
      if (!collision(x+i))
      {
        x++;
      }
    }
    well, something like that..

  7. #7
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: Java platformer, rect collision

    hmmm, what does var "dx" means?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  8. #8
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: Java platformer, rect collision

    dx is the number of pixels the character advances, in your case 3.

  9. #9
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: Java platformer, rect collision

    Hmm, I'll give it a try..
    WARNING I am Russian so it's possible that I wont understand you correctly...

Similar Threads

  1. Replies: 7
    Last Post: 12-03-2012, 09:31 PM
  2. Replies: 2
    Last Post: 04-08-2012, 11:58 PM
  3. Replies: 4
    Last Post: 10-17-2011, 08:09 PM
  4. Replies: 0
    Last Post: 10-15-2011, 10:56 PM
  5. MouseEntered to rect
    By g6pd in forum New To Java
    Replies: 3
    Last Post: 03-10-2011, 01:52 PM

Posting Permissions

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