Bartuken

Handle diagonal car ramp

Recommended Posts

Greetings from a newbie in Phaser.
 

In a 2d car game, how do you imagine a car ramp?

Is there any way to draw a diagonal object and when the car object hits that start decreasing the angle and increasing the position.y?

Progress!

I started with Phaser.Physics.P2JS ( had to quit using Phaser.Physics.ARCADE ) 
Then make an sprite and assigned a Polygon:

preload(){

  this.load.physics('physicsData', '/app/dist/sprites.json');

}

create(){

  game.physics.startSystem(Phaser.Physics.P2JS);
  game.physics.p2.gravity.y = 50;
  game.physics.p2.defaultRestitution = 0.01;

  ramp = game.add.sprite(100, 100, 200, 100, "block");
  game.physics.p2.enable(ramp);
  ramp.body.clearShapes();
  ramp.body.loadPolygon('physicsData', 'ramp');

}

My sprites.json is:

{
  "ramp": [
      {
		"density": 2, "friction": 0, "bounce": 0,
		"filter": { "categoryBits": 1, "maskBits": 65535 },
		"shape": [  200, 0 , 200, 100 , 0, 100  ]
	  }
  ]
}

giphy.gif

I think I got it.

Any advice is good

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.