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

Author Topic: Collision not detected  (Read 2526 times)

0 Members and 1 Guest are viewing this topic.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Collision not detected
« on: December 23, 2015, 12:00:30 pm »
Hi,
ok let me explain situation.
i have player sprite and blade.
my player position is 500,225.
blade position is 4500,250.

now i want to detect collision when blade touch the player , thats how i do it:
        FloatRect PlayerBound = sp.getGlobalBounds();
                        FloatRect BladeBound = blade_SP.getGlobalBounds();


                        if (PlayerBound.intersects(BladeBound)) {
                                u = 4;
                                death = 1;
                                cout << "detected";
                        }
i just follow the tutorial in sfml learning section why this will not work at all? what im doing wrong?
thanks
« Last Edit: December 23, 2015, 12:03:29 pm by raminlich »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Collision not detected
« Reply #1 on: December 23, 2015, 05:10:15 pm »
There is absolutely not enough information here to understand your problem.
Please post a complete and minimal example and describe the errors you are having.
You should also read that entire thread.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: Collision not detected
« Reply #2 on: December 23, 2015, 05:57:11 pm »
ok more info:


this is blade and player two sprites and this is my collision detection codes:

// player death
                        FloatRect PlayerBound = sp.getGlobalBounds();
                        FloatRect BladeBound = blade_SP.getGlobalBounds();


                        if (PlayerBound.intersects(BladeBound)) {
                                u = 4;
                                death = 1;
                                cout << "detected";
                        }
                        if (death == 1) {
                                if (DieOn <= 30) {
                                        window.draw(play.dieA.DoAnimation(np));
                                        DieOn++;

                                }
                                if (DieOn == 30)
                                        state = 2;
                               
                        }
                        // player death
I try say :
when playerBound touch BladeBound initialize some variables and do the dying animation
window.draw(play.dieA.DoAnimation(np));
but i dont know why blade always pass the player and collision code will not work.  :-[
i hope i have make it clear.
thanks

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: Collision not detected
« Reply #3 on: December 24, 2015, 12:53:54 pm »
is it still unclear?
please tell me whats wrong?
thanks

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Collision not detected
« Reply #4 on: December 24, 2015, 01:14:09 pm »
My crystal ball is broken...

Please post a complete and minimal example and describe the errors you are having.
SFML / OS X developer

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: Collision not detected
« Reply #5 on: December 24, 2015, 01:45:20 pm »
sorry its looks like my code is correct.
i do the mess some where else.
i have to figure out on my own.
thanks

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Collision not detected
« Reply #6 on: December 27, 2015, 05:28:30 am »
Just post problematic rectangle coordinates and size. But it seems that there is a problem with object physics (high speed relative to update interval), but not with FloatRect

 

anything