Jump to content

How can i decelerate using arcade physics ?


askariwa
 Share

Recommended Posts

I am trying to create a little game but i have this problem (for now  ;) ) :

 

At the "create" state i define 

 
this.collisionCircle = new Phaser.Circle(0,0,2);this.playerRectangle = new Phaser.Rectangle (0,0,0,0);this.player = game.add.sprite(game.world.centerX, game.world.height-80,'player');game.physics.arcade.enable(this.player);this.player.body.drag.set(550);this.circleCenter = new Phaser.Point(0,0);this.PointToGo = new Phaser.Point(0,0);
At the "update" step i have
collisionCircle.setTo(mycircle.center_x,mycircle.center_y,50);if ((Phaser.Circle.intersectsRectangle(collisionCircle,playerRectangle)) && (touchesPlayerAlready==false)){   touchesPlayerAlready=true;   circleCenter.setTo(mycircle.center_x,mycircle.center_y);   PointToGo=Phaser.Point.rotate(circleCenter, playerRectangle.centerX, playerRectangle.centerY, 180, true);   game.physics.arcade.accelerateToXY(player,PointToGo.x,PointToGo.y,20)} 

What i am trying to do is using the circular sprite to "push" the player sprite.

I define the coordinates of PointToGo as the diametrically opposite point of the circle center using the player sprite coordinates as the middle point of the rotation.

My problem is that, even setting the Drag property of player, the player sprite after the first intersection with the circular sprite does not decreases it's velocity but it always ends it's movement at the "borders" of the game (defined with a tilemap).

What i want to do is simulate a real-life push, something that at the beginning has an acceleration, caused by a force, but needs to have a deceleration of it's velocity caused by friction.

Maybe i am doing it wrong here by using the accelerateToXY method but i cannot find something like applyForce in arcade physics.

Can anyone help me with this ? 

 

 

Link to comment
Share on other sites

Have you tried applying the property Mass to the body of the sprites? Because as stated in the docs: 

 

 

 

The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity.

 

http://phaser.io/docs/2.3.0/Phaser.Physics.Arcade.Body.html#mass

 

Which sounds like the thing you want to achieve.

Link to comment
Share on other sites

Have you tried applying the property Mass to the body of the sprites? Because as stated in the docs: 

 

 

http://phaser.io/docs/2.3.0/Phaser.Physics.Arcade.Body.html#mass

 

Which sounds like the thing you want to achieve.

 

I really thank you for your help but i think i cannot use the mass property because i don't have a "body" for the circular sprite (since arcade physics don't handle circular bodies).

I know that using the arcade physics lib for this seems wrong but using the p2 lib would create me more problems with the rest of the game  :(

any more help ?

Link to comment
Share on other sites

The last three params to game.physics.arcade.collide are the collide callback, the process callback, then the context for both the callbacks. If you return true from the process callback then the collision callback will be called and you can do whatever you need to do.

 

You should try running your circle collision check in the process callback for your sprites, see if that works for you.

Link to comment
Share on other sites

Thank you drhayes but my problem is not the collision checking part but passing a bit of the kinetic energy of the circular spite to the player sprite.

Using the accelerateToXY method helps me indicate the correct vector of the force applied during the collision but the player sprite but i know that i'm setting an acceleration instead of an force. 

Isn't any way at all defining a force in arcade physics ?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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