Jump to content

collision processing


skaplun
 Share

Recommended Posts

Hey Guys,

Got a question about collisions in arcade before I start creating overly complex maneuvers :)

 

given two rotated sprites that can move in all directions, I want to be able to detect collision so that:

 

1. if player right side hits villain left side both die

2. if player right side hits villain on any side other than left only villain dies

3. if villain left side hits player on any side other than right only player dies.

 

I tried to do this with body.touchinng / body.facing and both don't seem to reflect the rotation of the sprites accurately.

 

So am I doing something wrong or should i create a collision handler based on rotation + position? or is there another option? 

 

What I have so far (which seems pretty useless):

 

    calculateImpact : function(player, enemy){
        var p = player.body.touching, 
            e = enemy.body.touching;
        
        
        if(p.right === true && e.left === true){
            this.tweens.removeFrom(player);
            
            player.kill();
            enemy.kill();
            
            this.explode(enemy);
        }
        else if(p.right === true && e.left === false){
            enemy.kill();
            this.explode(enemy);
        }
        
        else if(p.right === false && e.left === true){
            player.kill();
            this.explode(player);
        }
        
        
    },
    

 

Link to comment
Share on other sites

Make sure you're using P2 physics if your bodies are under rotation; Arcade physics only works with non-rotated rectangles ("Axially-Aligned Bounding Boxes" == AABBs).

 

P2 is definitely not my forte, but I *think* you want the onBeginContact signal on the P2 physics body your sprites will have once enabled. Your physics bodies will be a little more complex, with different shapes on each side of your sprite (if I understand your question correctly). That way you'll be able to tell which "side" was hit by what.

Link to comment
Share on other sites

Why use p2? I understood from reading here that p2 is too much for mobile. is that not true?

 

it seems that touching / facing does start to work if I register velocity.x + velocity.y on the body.

So i guess my problem is that tween between two points does not update the objects velocity.

 

Is this intentional? a bug that I should try to work around?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...