hexus / phaser-arcade-slopes

:triangular_ruler: A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine
MIT License
126 stars 16 forks source link

Anchor sprite bottom to slope #10

Closed yaegerbomb closed 7 years ago

yaegerbomb commented 7 years ago

Is there a way to make sure that the sprite that is colliding with the slopes rotates in the direction to where the slope is?

Scenario: Sprite is a roller coaster cart. As it goes up the hill i want the cart to stay attached to the ground so that sprite needs to rotate to match the slope. Same for going downhill.

Am I provided with information in my collision callback that might help me achieve the correct rotation?

hexus commented 7 years ago

While this was only intended for axis-aligned bounding boxes for now (and circles soon) there is data given to the physics body that could be useful to you for this.

In your callback, access sprite.body.slopes.sat.response. It's an SAT.js response object from the collision that gives you information about the collision; the direction and the depth.

Keep in mind, this response will always be in regards to the original axis-aligned bounding box so it might not be easy to get the consistent results you want. This plugin hasn't been written with rotation in mind, but in future, it could...

yaegerbomb commented 7 years ago

Awesome. It will be a good start for now and that is all I was looking for with the initial question. Thanks!

hexus commented 7 years ago

Nice one. Happy to have helped. :+1: