zargap

Collision help

Recommended Posts

Hi friends, new to the forum and to Phaser.

 

Basically I'm trying to get my bearings and right now I'm just sorta turning the "Making your first Phaser game" tutorial http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game into a more RPG-style dealy. 

 

My issue is that my sprite-to-sprite collisions seem to be working well, but if say I walk into a sprite headed right, bump into another sprite and then go a bit up or a bit down, sometimes I can continue through the sprite by heading further right.

I don't have this problem with tileset collisions.

 

Here's what I have for movement:

 

//LEFT            if (cursors.left.isDown) {                if (player.body.touching.left) {                    player.x += 3;                }                else {                    player.body.velocity.x = -100;                    player.animations.play('left');                }//RIGHT            } else if (cursors.right.isDown) {                if (player.body.touching.right) {                    player.x -= 3;                }                else {                    player.body.velocity.x = 100;                    player.animations.play('right');                }//UP                             } else if (cursors.up.isDown) {                if (player.body.touching.up) {                    player.y += 3;                }                else {                    player.body.velocity.y = -100;                    player.animations.play('stand');                }//DOWN                            } else if (cursors.down.isDown) {                if (player.body.touching.down) {                    player.y -= 3;                }                else {                    player.body.velocity.y = 100;                    player.animations.play('stand');                }            }             /*else if (cursors.up.isUp)    {        player.body.velocity.y = 0;        player.animations.stop();    }    else if (cursors.down.isUp)    {        player.body.velocity.y = 0;    }*/            else {                //  Stand still                player.animations.stop();                player.frame = 4;                player.body.velocity.x = 0;                player.body.velocity.y = 0;            }        }
And for collisions:
 
game.physics.collide(player, mans);
 
Is it something I did? Am I doing something really inelegant and unnecessary or something? Should I add something with overlaps?
 
Thanks in advance.

Share this post


Link to post
Share on other sites

try using velocity to move the sprites instead of directly manipulating their position - I believe directly changing their position overrides the physics engine and collision handling won't work properly

Share this post


Link to post
Share on other sites

1.1.3 (and previous) had issues where sprites could be forced into each other and into tiles if "pushed hard enough". if you search the forums you'll find threads on this issue.

 

the physics in 1.1.4 was re-written to fix this. unfortunately, at present, issue #362 means that some collisions don't seem to happen at all.

Share this post


Link to post
Share on other sites

Yes, this is in 1.1.4. 

 

If I don't have the bit that checks if they're touching and bumps the sprite a bit, it's a lot easier to just walk through things, but I guess I'll just take that out and wait for it to get fixed, thanks for clearing this up (more or less).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.