Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Collision Detection  (Read 2394 times)

0 Members and 1 Guest are viewing this topic.

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
Collision Detection
« on: November 24, 2010, 12:52:47 am »
hello, right now im having a bit of a dilemma with my collision detection. its not en error but more like a glitch.

heres the code:

Code: [Select]
if(Game.GetInput().IsKeyDown(sf::Key::W))
            {
                Atheyy.SetSubRect(sf::IntRect(34,0,51,22));
                if(Collision::PixelPerfectTest(PlayyCol,PlayyMapCol,1))
                {

                }
                else
                {
                    Atheyy.Move(0,-0.3);
                    View.Move(0,-0.3);
                    PlayyCol.Move(0,-0.3);
                }


the problem is:
when i move everythings fine, but when i collide with said sprite then i cant move at all.

i have also tried making a different sprite jsut for collision.

basically im asking if i did this right.

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Collision Detection
« Reply #1 on: November 24, 2010, 03:00:01 am »
Look at your code. If you collide then you skip the movement.

Since you skip the move, then you never change your current position, meaning you are still colliding.

And since you are still colliding when you try to move, you trigger the if statement and skip the movement again. So you will never move. Learn how your debugger works and then step through this code peice, you'll see why it behaves the way it does instantly.  :D

You need to add code to the top part of your if statement to actually resolve the collision(kill the sprite or move it so that it's no longer colliding). Other than that, it does pretty much what you want it to.

I hope that makes sense, it's hot in australia and my brain might be working slower than my keyboard.

molmasepic

  • Newbie
  • *
  • Posts: 43
    • View Profile
Collision Detection
« Reply #2 on: November 24, 2010, 07:11:08 pm »
i have once tried moving the player back once he makes contact, but when doing that, it just bounces back very fast....almost like vibrating. basically im wondering if theres a way to check for collision BEFORE i collide, thus preventing them problem. also the tutorial doesnt make alot of sense to me xD



EDIT: if this is not possible, then ill just need to find a pretty good physics engine for code blocks/MingW. if you guys know any then please reply. and if THATS not possible then ill need to know what IDE/compiler i should use(free is preferred) Also im using Win32bit

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Collision Detection
« Reply #3 on: November 26, 2010, 04:33:21 am »
Quote from: "molmasepic"
i have once tried moving the player back once he makes contact, but when doing that, it just bounces back very fast....almost like vibrating. basically im wondering if theres a way to check for collision BEFORE i collide, thus preventing them problem. also the tutorial doesnt make alot of sense to me xD



EDIT: if this is not possible, then ill just need to find a pretty good physics engine for code blocks/MingW. if you guys know any then please reply. and if THATS not possible then ill need to know what IDE/compiler i should use(free is preferred) Also im using Win32bit


You should try and get the previous pixel and put the else as moving it back to previous pixel so it will look like its just stuck there but you can still move... Because you are only moving 1 pixel so really no one can tell...

 

anything