Jump to content

[1.1.5] Weird collision problem


ZRT
 Share

Recommended Posts

Hey guys,

 

I have a weird collision in my 1.1.5 game, sprite VS sprite. I've read on this forum about similar stuff, but not sure it's the same issue that was in 1.1.3 and fixed in 1.1.4. Tried it with 1.1.3, works the same.

 

I made a quick ugly sketch to demonstrate the behavior. The collision works from left and right and top/bottom of the rectangle. But when it "cuts " the edge of it, it just goes through.

 

9Mh7Mov.png

 

Here's the code:

    if (this.game.physics.collide (this.player, this.obBot)) {      this.player.kill();      game.state.start('Over');    }    if (this.game.physics.collide (this.player, this.obTop)){      this.player.kill();      game.state.start('Over');    }

Thanks.

 

EDIT: Another issue is that the collision sometimes happens few pixels BEFORE it touch the sprite.

Link to comment
Share on other sites

I just found what the problem was.

    this.player = game.add.sprite(70, 100, 'player');    this.player.body.setCircle(20);    this.player.body.gravity.y = 600;    this.player.body.bounce = 0.5;    this.player.body.collideWorldBounds = true;    this.rotation = this.game.add.tween(this.player).to({angle: this.player.angle + 120});    this.rotation.start();

The last two lines that add rotation. The player sprite is actually a ball that enters the scene rotating and stops when the movement input is triggered. I removed those two lines and the collision works as intended. Is there any neat way that I can make the sprite rotate without causing the problem in first post? Thanks.

 

EDIT: I don't think I even need tween here.

Link to comment
Share on other sites

Yeah, doesn't rotate in my game. Works fine in your demo. Still trying to make it work. The problem is whenever I add an angle, it rotates weirdly. I moves the sprite position and that's why the collision happens even before both images collide.

 

I must be doing something wrong and stupid and I will post as soon as I fix it. :) Thanks again.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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