koko Posted January 13, 2016 Share Posted January 13, 2016 Hi, this is my first post and probably a newbie mistake, I'm trying to get collisions working between two objects. What I have is overlap() works but collide() doesn't. All being equal when I substitute overlap for collide in code below the collision is no longer detected. Any thoughts on why it may be so? First I setup the engine: this.game.physics.startSystem(Phaser.Physics.ARCADE); Then set up the objects: this.platform = this.game.add.sprite(471, 535, null); game.physics.enable(this.platform, Phaser.Physics.ARCADE); this.platform.body.immovable = true; this.platform.body.setSize(200,10, 0,0); and this: this.cube = game.add.sprite(x, y - 30, 'characters', 'cube1'); this.cube.anchor.setTo(0.5, 0.5); game.physics.enable(this.cube, Phaser.Physics.ARCADE); And in the update() collide/overlap them like that: game.physics.arcade.overlap(this.platform, this.cube, function (platform, cube) { this.unloadCube(); game.paused = true; }, null, this); This is just part of the code. For what it's worth, cube is in a group and is moved with it's parent. The platform is on the root level. Link to comment Share on other sites More sharing options...
drhayes Posted January 13, 2016 Share Posted January 13, 2016 Are the two things involved in the collision moving, like they both have velocities? Link to comment Share on other sites More sharing options...
koko Posted January 13, 2016 Author Share Posted January 13, 2016 One is moving the other is static. But the moving one is attached to a group and I move the group by x and y. Now from the other thread I learned that I need to move the bodies with velocity in order for collisions to make any sense, so moving a group makes no sense probably and I need to use a sprite with children? Link to comment Share on other sites More sharing options...
drhayes Posted January 13, 2016 Share Posted January 13, 2016 If you move the sprite with children (and the thing you care about colliding is one of the children) then it'll only collide with the parent, not the child. Why the group and moving everything in it? Link to comment Share on other sites More sharing options...
koko Posted January 14, 2016 Author Share Posted January 14, 2016 Well, I'm quite new to phaser so I don't know all the options yet and group was the first ting I found. As I wrote elsewhere, I have a character carrying an object and I need to check if the object is put on a surface. For now I use overlap for that but for what I know it doesn't support directions so I have to manually check if it's ON and not UNDER or BESIDE the table surface. So basically my question is what's a best way to satisfy these assumptions? The collided object is carried around with a sprite which shouldn't collide The object should collide with another (immovable) object I want to know the direction of the collision (ie. the side of immovable object that was hit) Link to comment Share on other sites More sharing options...
drhayes Posted January 14, 2016 Share Posted January 14, 2016 In Arcade physics, the bodies have a property called "touching". "body.touching.down" means the body collided on the bottom. Would that work? There's another property, "blocked", for when the body collides with the world boundaries or a tile. You might end up having two separate sprites whose positions you keep in sync manually, instead of making one of them a child? Or, you could make them both children but then check each of them directly instead of the parent? Link to comment Share on other sites More sharing options...
koko Posted January 14, 2016 Author Share Posted January 14, 2016 There are slight rotations involved so I'd rather put them in one container. Yeah, I'd check each directly as I do now, I only wonder if they inherit parent's velocity which is needed for collisions? I'll test that, thanks anyway! Link to comment Share on other sites More sharing options...
Recommended Posts