AlexArroyoDuque Posted March 16, 2014 Share Posted March 16, 2014 Hello. I want to use the physic arcade with objects that have physic p2. I get an error console. Uncaught TypeError: Can not call method 'setTo' of undefined Any help with that? Link to comment Share on other sites More sharing options...
valueerror Posted March 16, 2014 Share Posted March 16, 2014 i think rich wrote somewhere that every physics body can just belong to ONE physics system.. therefore you should not be able to collide a p2 physics body with an arcade physics body or apply any arcade physics to a p2 body Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 16, 2014 Author Share Posted March 16, 2014 Hello! The two objects that I want to apply physics are P2. It is an enemy that follows the player. Before I used "accelerateToObject" but now I do not know how to get the same result ... Link to comment Share on other sites More sharing options...
valueerror Posted March 16, 2014 Share Posted March 16, 2014 Quote: "physic arcade with objects that have physic p2." sorry.. to me that sounded like you want to combine arcade and p2 physics.. so you want to know how to set something up in p2 that formerly worked in arcade... i think you'll have to post more code... or even provide a link to the testcase Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 16, 2014 Author Share Posted March 16, 2014 Piece of my code create: this.player = this.game.add.sprite(170, 50, 'player'); this.game.physics.p2.enable(this.player, true); this.player.body.setRectangle(33, 78); this.snakes = this.game.add.group(); this.snakes.create(900, 80, 'snake'); this.snakes.forEach(enemy.setupSnake, this); update: this.snakes.forEach(enemy.moveSnake, this); //aux functions enemy.setupSnake = function(snake) { this.game.physics.p2.enable(snake); snake.body.setRectangle(30, 45); snake.health = 2; }; enemy.moveSnake = function(snake) { this.game.physics.arcade.accelerateToObject(snake, this.player, utils.rangeRandom(90, 100), utils.rangeRandom(120, 130)); } Link to comment Share on other sites More sharing options...
valueerror Posted March 17, 2014 Share Posted March 17, 2014 so you ARE trying to combine p2 with arcade ... thats what i meant.. AFAIK you can not use arcade stuff on p2 bodies.. but have a look here: http://test.xapient.net/phaser/moveto.html i found your problem interesting and tried to solve it.. i think i found a way to do what you want with p2.. but it's very complicated ^^i do not fully understand it myself as i just combined different approaches i saw in one of rich's lab examples... have a look at this function i wrote: function moveBullets (bullet) { var dx = ship.body.x - bullet.x; var dy = ship.body.y - bullet.y; bulletRotation= Math.atan2(dy, dx); bullet.body.rotation = bulletRotation + game.math.degToRad(-90); var angle = bullet.body.rotation + (Math.PI / 2); bullet.body.velocity.x = 50 * Math.cos(angle); bullet.body.velocity.y = 50 * Math.sin(angle);}it rotates the bullets to the "ship" object and then sets x and y velocity according to the angle.. you need to call this function on every bullet (or snake) in the update loop (and "ship" needs to be a global) bullets.forEachAlive(moveBullets,this); DanielKlava, AlexArroyoDuque and spiritabsolute 3 Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 17, 2014 Author Share Posted March 17, 2014 Another post more and you help me. Thank you very much. I will try to use your method. I do not understand exactly why phaser have limited physical p2 with useful things in the ARCADE system. Link to comment Share on other sites More sharing options...
valueerror Posted March 17, 2014 Share Posted March 17, 2014 p2 is very new... it just got introduced to phaser with 2.0 a few days ago.. while arcade physics was there from the beginning.. i guess rich will make sure that p2 will have the same useful and easy to use functions when he finds the time to implement them.. let's just wait and see Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 17, 2014 Author Share Posted March 17, 2014 I say this because it is a little frustrating to migrate. We have to wait then. Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 18, 2014 Author Share Posted March 18, 2014 Hello! I used your method but simplified, with enemies that move only horizontally and works ok. But when an enemy make bullets, the bullets do not move. You know why? A greeting. Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 19, 2014 Author Share Posted March 19, 2014 I put a console log(bullet.body.velocity.x);And the result is incorrect... Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 19, 2014 Author Share Posted March 19, 2014 Solved. var enemyBullet = this.enemyBullets.getFirstDead(); // var enemyBullet = this.enemyBullets.getFirstExists(false); Link to comment Share on other sites More sharing options...
Recommended Posts