Jump to content

prevent collision before positioning objects


maxxxir
 Share

Recommended Posts

i've updated this question ... i couldn't edit the title to something mor appropriate

---------------------------------------

 

 

 

im trying to build a pool game as my first phaser project

the biggest challenge today was to make the cue rotate around the white ball ... after hours of searching and not finding anything useful (there is a example about rotating points but no sprits ) i was able to crate something , not very clean but it works



here is the white ball


 

        balls = game.add.group();        balls.enableBody = true;        balls.physicsBodyType = Phaser.Physics.P2JS;        wball = balls.create(350, 240 , 'ballW');        wball.body.setCircle(15);        wball.body.setCollisionGroup(wballCollisionGroup);        wball.body.collides([wballCollisionGroup, ballsCollisionGroup , sidesCollisionGroup , holesCollisionGroup , playerCollisionGroup]);                    game.physics.p2.setImpactEvents(true);

here is the cue which i call it player


 

player = game.add.sprite( 0 , 0 , 'player');game.physics.p2.enable(player);player.enableBody = true;player.body.setCollisionGroup(playerCollisionGroup);player.body.setZeroVelocity();player.body.createBodyCallback(wball, ballHit , this);player.anchor.setTo(-0.5, 0.5);player.pivot.x = wball.x +150;player.pivot.y = 0;player.body.x = wball.x ;setTimeout(function(){player.body.y = 150 ;} , 1000 );setTimeout(function(){player.body.y = 200 ;} , 2000 );setTimeout(function(){player.body.y = 240 ;} , 3000 );

as you can see i have set the y position for player in 3 steps to demonstrate the problem

it starts at the top of the page and comes down .. as soon as i set y=240 which is the wball y a collision happens even tough we can see clearly they are not colliding !

pleas note both codes are in the create function here is the live code

http://199.26.84.223/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...