phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.94k stars 7.08k forks source link

Arcade Physics Immovable Body Issue #644

Closed momo-the-monster closed 10 years ago

momo-the-monster commented 10 years ago

I'm doing an overlap check on two bodies: one projectile and one immovable. The projectile dies on overlap, the immovable should scale down. If I scale it down, it flies off the screen in the direction the projectile was pushing it, even though its body is set to be immovable.

Demo at http://codepen.io/momothemonster/pen/luIJq

photonstorm commented 10 years ago

Make sure you are using the version of 2.0.1 that we released today. But then try adding this:

icon.body.moves = false;

As well as immovable. With that in place it seems to work as expected here, although it's a good question why it needs it. Right now I'm not really sure, will need to investigate further, but I suspect the scale was making it think it had velocity for some reason, and it just carried on moving. The direction was nothing to do with the bullet that hit it, had you scaled it to 1.2 it would have moved somewhere else entirely.

momo-the-monster commented 10 years ago

indeed, icon.body.moves = false fixes the issue. It's worth noting that: icon.body.immovable = true makes no difference in this case.

(I should have mentioned what version I was working from - I built Phaser from the latest dev just before I built the demo).

photonstorm commented 10 years ago

Sure, the issue is purely to do with the scaling re-positioning the body. It could also be stopped by setting a max delta value for the body as well, but I'd rather find out why it's happening in the first place.

jasoncyoun commented 10 years ago

I'm seeing something similar. When I'm scaling to flip a sprite, then change the anchor point so that the sprite stays inside the bounding box, the sprite flies off to the left as if it had a velocity set to it. This does not happen in version 2.0.

jcalonso commented 10 years ago

I think I have the same issue, my sprite goes to the bottom right corner with this code:

this.player = this.add.sprite( 100, 0, 'player' );
this.player.anchor.setTo( 0.5, 0.5 );
this.physics.enable( this.player, Phaser.Physics.ARCADE );
this.player.scale.set(0.4);
photonstorm commented 10 years ago

Just so you know I've fixed this properly in the dev branch and will probably push out 2.0.2 later today to get it into wider circulation.

jasoncyoun commented 10 years ago

woohoo! thanks!

jcalonso commented 10 years ago

Excellent!