Jump to content

[WIP] Metroid Fusion Clone


loafer
 Share

Recommended Posts

No I didn't use ninja, I wrote slope functions for arcade physics.

 

Below you can see the function I wrote for a one-tile slope facing right. Hope it helps someone.

function (i, body, tile) {        /*          .__          |  |        a |  |        |\p__|        | \        |__\        c   b        */        var collides = Phaser.Physics.Arcade.isPointInTriangle(            body.position.x,                // px            body.position.y + body.height,  // py            tile.worldX - tile.width,       // ax            tile.worldY - tile.height,      // ay            tile.worldX + (tile.width * 2), // bx            tile.worldY + (tile.height * 2),// by            tile.worldX - tile.width,       // cx            tile.worldY + (tile.height * 2) // cy        );        if (collides && body.position.x >= tile.worldX) {            body.y = tile.worldY - body.height + (body.position.x - tile.worldX);            if (body.y < tile.worldY - body.height) {                body.y = tile.worldY - body.height;            }            if (body.y > tile.worldY + tile.height - body.height) {                body.y = tile.worldY + tile.height - body.height;            }            body.velocity.y = 500;            body.blocked.down = true;            return false;        }        return true;    }
Link to comment
Share on other sites

  • 3 weeks later...

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...
 Share

  • Recently Browsing   0 members

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