• Content Count

  • Joined

  • Last visited

About Yanifska

  • Rank
    Advanced Member
  • Birthday 07/14/1982

Contact Methods

  • Website URL
  • Twitter

Profile Information

  • Gender

Recent Profile Visitors

867 profile views
  1. Hi there, is there a specific way to remove a constraint like lockConstraint ?
  2. I just mean the part about sensors, there is nothing about sensors in phaser docs nor examples, a link to the p2.js website should be added as well. It is very confusing at first
  3. Hi, I have obstacles attached to a revolving planet with a lockConstraint. When the player hit an obstacle I want him to get stuck on the obstcale. I try to do that also with a lock constraint but I got many problems: 1. the obstacle rotate a littlebit on it own axis 2.the character don't get it's rotation updated according to the planet rotation here are bits of code // set up the obstacle groupthis.obstacles = this.game.add.group();this.obstacles.createMultiple(20, 'kit');this.obstacles.forEach(function(obstacle) {obstacle.anchor.setTo(0.5,1);this.game.physics.p2.enable(obstacle, true);obstacle.kinematic = true;}, this);//for now a timer add the obstaclesaddObstacle: function () {var obstacle = this.obstacles.getFirstDead();obstacle.reset(960, 960);obstacle.scale.setTo(this.game.rnd.integerInRange(3, 7),this.game.rnd.integerInRange(3, 7));obstacle.body.setRectangle(obstacle.width, obstacle.height);obstacle.angle = 90;obstacle.body.setCollisionGroup(this.obstacleCollisionGroup);obstacle.body.collides(this.playerCollisionGroup);//correct the position according to the rotation of the planetvar correctAngle = this.planetDummy.rotation * -1;var x1 = this.ground.height + obstacle.height*0.5;var y1 = 0;var x2 = x1*Math.cos(correctAngle) - y1*Math.sin(correctAngle);var y2 = x1*Math.sin(correctAngle) + y1*Math.cos(correctAngle);var initRotation = obstacle.rotation - this.planetDummy.rotation;this.game.physics.p2.createLockConstraint( this.planetDummy, obstacle, [ x2*-1, y2*-1], initRotation);},//the playerthis.player = this.game.add.sprite(BasicGame.gameWidth * 0.5, this.ground.y - this.groundblock1.height - 100, 'thief');this.player.anchor.x = 0.5;this.player.anchor.y = 2; this.game.physics.p2.enable(this.player,true);this.player.body.setRectangle(90,200);this.player.body.fixedRotation = true;//add a sensor to detect side collisionthis.playersensor = this.player.body.addRectangle(15, this.player.height * 1.2, this.player.width * 0.33 ,0);this.playersensor.sensor=true;this.player.body.setCollisionGroup(this.playerCollisionGroup);this.player.body.collides(this.obstacleCollisionGroup);this.player.body.collides(this.groundCollisionGroup);//if the sensor detect a collision it runs the hitObstacle functionthis.player.body.onBeginContact.add(this.hitObstacle,this);//when the character sensor detect a collisionhitObstacle: function (bodyA,shapeA,shapeB,contactEquation) {if(shapeA.sensor && !this.gameOver){this.gameOver = true;his.player.body.fixedRotation = false;//so it will get its rotation updatedthis.groundDummy.body.clearCollision(true,true);var lockConstraint = this.game.physics.p2.createLockConstraint(bodyA, this.player, [bodyA.sprite.width*0.5, bodyA.sprite.y - this.player.y], 0);lockConstraint.collideConnected = false;}},// in the update functionthis.planetDummy.body.rotateLeft(12);this.player.body.velocity.x = 0;this.obstacles.forEach( this.obstacleOut, this);any idea ? thank Yaniv
  4. this.bullet.body.sensor = true or something similar. this is how I do it in my game : this.playersensor = this.player.body.addRectangle(15, this.player.height * 1.2, this.player.width * 0.33 ,0);this.playersensor.sensor=true; here it's just ts a second shape on the same sprite, the main shape manage the collision, wile the sensor just check if a specific side is colliding, I don't need it to trigger physic response so I set it as a sensor
  5. Thanks it helped a lot Edit: maybe it should be added as an example in the phaser example repository ?
  6. thank man, I see you are using onBeginContact I was trying to use multiple collide functions each one on specific shapes, but it doesn't seems to work, I guess it should be possible since there are way to specify what shape and groups to collide with. I will try your stuff, however I am a bit in doubt because I have collision groups. In my case the situation is quite opposite, I want each obstacle to have its own sensor Maybe I should have a sensor in front of the character.... That gives me ideas...
  7. hI there, I want to use the main body of a sprite for collisions only, for some kind of platform, and add an invisible sensor that will detect collision only on one side of the sprite and trigger a death reaction. Basically the character can jump on the top of the sprite, but touching the side will trigger the "die" fucntion. My question is: Should I use addRectangle ? it seems to work and it adds a "second body". However how do I detect collision with this second body ? Also is doesn't seems to collide like the main boddy, so what does the sensor property will do ? Edit: I didn't set up collision for the sensor, so I guess that's why it is not colliding, so how do I detect collision / overlap from the sensor ?
  8. I think you can do something like var myRotation = mySprite.angle; var myRotation = mySprite.rotation;
  9. I have been looking into these, but I am having a hard time understanding all that. So I am going back to p2 for know I managed to collide rotating rectangles. My problem now is how to rotate am object around another, is the "revolute constraint" the right and only way to go ?
  10. Hey man, thanks for all I tried to look in for SAT and indeed it looked a bit too complex for me, I wasn't able to find any JS functions by myself, I'll try and look deeper into that. Concerning the bug, please just try the protoype in the link I provided (Just click to jump.) http://www.yanivcahoua.com/examples/aeroboy/ Here the collision are working fine for a moment but at acertain point the character hit an invisible wall... and don't undestand why. Also it seems that some of the obstacle are not showing up somehow.... Here is the source file http://www.yanivcahoua.com/examples/aeroboy/src/Game.js Basically what I do is I create (reset) the obstacles at a specific place and attach them to the obstacles group and then correct the position so they won't jump ( becuase og the offset in world to local space and rotation). The function seems to be ok, but something is inconsistent no matter what I try ( I tried Arcade and and a very little bit of P2 and a few variation of a custom engine). Anyways Thank you a lot
  11. Another problem I have, is sometime my character will crash into the air, It always will crash in the tenth obstacle that has just been generated,, but somehow is still far behind. So I don't understand why...
  12. In fact I think I am doing something a bit unusual wich involve a lot of rotation and I understood it would be rather difficult to do in a physic engine. It needs to stay quite simple that's why I thought I could manage it all by my self. Check it there, just click to jump: http://www.yanivcahoua.com/examples/aeroboy/ Obviously, the bounding box is problematic How would you group the rotating obstacles and then check for collisions for the character ? THANX GUYS !!!
  13. Are there any tutorial for this Engine, I am having a hard time with it. I was trying to build my own engine. But that's way too much for me Thanks
  14. Hi there Is there a way to check collisions of rotated rectangles in phaser ? Thanks Yaniv
  15. I finally got rid of any physics engine and managed all the collisions by myself.