Giter Site home page Giter Site logo

hexus / phaser-arcade-slopes Goto Github PK

View Code? Open in Web Editor NEW
125.0 7.0 16.0 3.89 MB

:triangular_ruler: A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine

License: MIT License

JavaScript 100.00%
phaser phaser-plugin phaser-arcade-physics slope tile collision separating-axis-theorem tilemap

phaser-arcade-slopes's Introduction

Phaser Arcade Slopes Plugin

Arcade Slopes brings sloped tile collision handling to Phaser's Arcade Physics engine.

Check out the demo!

Phaser Arcade Slopes

Features

  • 24 new tile types ๐ŸŽ‰
  • SAT collision handling ๐Ÿ‘Œ
  • Unobtrusive and cooperative integration with Arcade Physics โœŒ๏ธ
  • Supports sprites ๐Ÿš€, groups ๐Ÿ‘ฅ, particle emitters โœจ and circular physics bodies โšช

Compatibility

Phaser Version Arcade Slopes Version
v2.4.1 - v2.4.8 v0.1.0
v2.5.0 - v2.10.1 v0.1.1 - v0.3.2
v3.x hexus/phaser-slopes

Installation

Grab a copy of the latest release from the dist directory in this repository and include it after Phaser.

<script src="phaser.min.js"></script>
<script src="phaser-arcade-slopes.min.js"></script>

Usage

Enabling the plugin

Enable the plugin in the create() method of your Phaser state.

game.plugins.add(Phaser.Plugin.ArcadeSlopes);

Mapping tiles

The plugin provides a couple of built in tile slope mappings:

After you've created a tilemap with a collision layer, you'll need to convert that layer to work with Arcade Slopes.

// Create the tilemap and make it aware of the tileset it uses
map = game.add.tilemap('tilemap');
map.addTilesetImage('collision', 'arcade-slopes-32');
map.setCollisionBetween(1, 38);

// Create the collision layer from the tilemap
ground = map.createLayer('collision');

// Convert the collision layer to work with Arcade Slopes
game.slopes.convertTilemapLayer(ground, 'arcadeslopes');

In the case that the first tile ID of the collision tileset in your tilemap is not 1 (the default), you can provide a third argument to specify it. The arguments provided to the setCollisionBetween() method may need to be adjusted as well.

map.setCollisionBetween(16, 53);
game.slopes.convertTilemapLayer(ground, 'ninja', 16);

Please note: Tile GIDs in maps exported from Tiled are always one more than the ID shown in the GUI. Arcade Slopes expects the above parameter to match the first GID as specified in the Tiled map data.

Enabling physics bodies

Now you need to enable slopes for any game entities you want to collide against the tilemap.

game.physics.arcade.enable(player);

game.slopes.enable(player);
game.slopes.enable(emitter);

You don't need to do anything special for circular physics bodies, just the usual sprite.body.setCircle(radius).

Make sure you call game.slopes.enable(object) after making any changes to the size or shape of the physics body.

Collision

Now you can collide your sprite against the tilemap in the update() method of your Phaser state, as you normally would, using Arcade Physics. Voila!

// Collide the player with the collision layer
game.physics.arcade.collide(player, ground);

// Collide the particles with the collision layer
game.physics.arcade.collide(emitter, ground);

Debug rendering

To debug your collision layer, set its debug property to true.

This will overlay the collision shapes of each tile when the layer is rendered.

ground.debug = true;

Extras

Minimum Y offset

This feature separates rectangular physics bodies on the Y axis only, in the right situations.

// Prefer the minimum Y offset for this physics body
player.body.slopes.preferY = true;

// Prefer the minimum Y offset globally
game.slopes.preferY = true;

If you're making a platformer, your player has drag on the X axis, and you don't want it to slide down slopes, this should solve your problem.

Collision pulling

To attempt to keep objects on a surface, you can use collision pulling.

This will pull physics bodies into a collision by a set velocity, if it matches the set direction.

// Pull the player into downwards collisions with a velocity of 50
player.body.slopes.pullDown = 50;

Here are the available properties for collision pulling:

body.slopes.pullUp
body.slopes.pullDown
body.slopes.pullLeft
body.slopes.pullRight
body.slopes.pullTopLeft
body.slopes.pullTopRight
body.slopes.pullBottomLeft
body.slopes.pullBottomRight

Building

If you want to build the plugin yourself from source, clone the repository and run NPM and Gulp like so.

npm install
gulp build

There's also a watch task that builds the plugin whenever you make changes to the source.

gulp watch

Thanks

My thanks go out to those who made this Plugin possible.

And to contributors who have been generous with their time, talents and support:

phaser-arcade-slopes's People

Contributors

hexus avatar ikonone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

phaser-arcade-slopes's Issues

Fix skipped collisions between tiles

There's an issue with heuristics that skip collisions between tiles.

Small enough objects can slip between tiles, as seen here:

https://github.com/photonstorm/phaser-ce/issues/94#issuecomment-290867117

Reproduce and fix the hell out of it without touching SAT.js for the time being.

This is related to #36. Disabling heuristics fixes the issue so that's likely where the it lies.

False Collisions

falsecollision

As seen in the example gif, the cowboy looking thing is moving at x speed and once it hits the corner, it is stopped and begins accelerating again. The expected behavior would be for it to continue without 'catching' the corner.

I haven't investigated the cause yet.

Corner collision pulling

Implement corner settings for collision pulling.

For example, bottomLeft would pull in the case of these collision vectors (facing in): overlapN.x < 0 && overlapN.y > 0.

This allows, in the example of a platformer with gravity, to pull a body into slopes but not on flat surfaces below (i.e. pull.bottomLeft, pull.bottomRight, but not pull.down).

Ideally for 0.1.1, but 0.2.0 would be fine.

Anchor sprite bottom to slope

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?

Flag internal polygon edges

Currently, tiles have each bounding box edge flagged if they are internal, but no such check is done for the vectors that the actual polygon comprises of.

This would be useful for restricting testable edges when raycasting, especially with ray bouncing.

Snaps to square even when snap is set to 0

Video example of https://rangersteve.io
https://streamable.com/koh2

Just a consts file

    // Slope Plugin
    SLOPE_FEATURES: {
        acceleration: 1500,
        bounceX: 0,
        bounceY: 0,
        debug: 0,
        dragX: 1300,
        dragY: 0,
        enableGravity: true,
        frictionX: 0,
        frictionY: 0,
        gravity: 1100,
        jump: 400,
        minimumOffsetY: 1,
        pullDown: 0,
        pullLeft: 0,
        pullRight: 0,
        pullUp: 0,
        snapDown: 0,
        snapLeft: 0,
        snapRight: 0,
        snapUp: 0
    },

Where I set the player's slope very similarly to how it's done in the demo.

const body = this.player.body

    this.physics.arcade.gravity.y = GameConsts.SLOPE_FEATURES.gravity

    // Add a touch of tile padding for the collision detection
    body.tilePadding.x = 1
    body.tilePadding.y = 1

    // Set player minimum and maximum movement speed
    body.maxVelocity.x = GameConsts.MAX_VELOCITY_X
    body.maxVelocity.y = GameConsts.MAX_VELOCITY_Y

    // Add drag to the player that slows them down when they are not accelerating
    body.drag.x = GameConsts.SLOPE_FEATURES.dragX
    body.drag.y = GameConsts.SLOPE_FEATURES.dragY

    // Update player body Arcade Slopes properties
    body.slopes.friction.x = GameConsts.SLOPE_FEATURES.frictionX
    body.slopes.friction.y = GameConsts.SLOPE_FEATURES.frictionY
    body.slopes.preferY    = GameConsts.SLOPE_FEATURES.minimumOffsetY
    body.slopes.pullUp     = GameConsts.SLOPE_FEATURES.pullUp
    body.slopes.pullDown   = GameConsts.SLOPE_FEATURES.pullDown
    body.slopes.pullLeft   = GameConsts.SLOPE_FEATURES.pullLeft
    body.slopes.pullRight  = GameConsts.SLOPE_FEATURES.pullRight
    body.slopes.snapUp     = GameConsts.SLOPE_FEATURES.snapUp
    body.slopes.snapDown   = GameConsts.SLOPE_FEATURES.snapDown
    body.slopes.snapLeft   = GameConsts.SLOPE_FEATURES.snapLeft
    body.slopes.snapRight  = GameConsts.SLOPE_FEATURES.snapRight

Remove the snap feature

It's caused trouble for users in the past and hasn't proven particularly useful anyway.

To be removed for 0.3.0.

Using Slopes in Typescript

Although there's a .d.ts file, it's not clear how the arcade-slopes API can be used in Typescript. Can you please provide sample code to enable and use the Slopes #plugin?

Overlap doesn't appear to account for empty space and overlaps them with ground

UPDATE

See down the conversation, the collide behavior looks like it's correct but you can't use overlap yet.
#7 (comment)

OLD
The bullets hit the 50% slope and slide up.
bullets5

The bullets go straight through and if you're shooting through a 10x10 the bullet will enter one side and collide with the opposite side.
bullets5

This is how I create 50 reusable bullets.

    this.bullets = this.game.add.group()
    this.bullets.createMultiple(50, 'bullet')
    this.bullets.setAll('checkWorldBounds', true)
    this.bullets.setAll('outOfBoundsKill', true)
    this.physics.arcade.enable(this.bullets)
    this.game.slopes.enable(this.bullets)

This is how I fire a bullet.

    let bullet = this.rootScope.bullets.getFirstDead()
    bullet.bulletId = Guid()
    bullet.damage = this.damage
    bullet.weaponId = this.meta.id
    bullet.height = this.bulletHeight
    bullet.width = this.bulletWidth
    bullet.alpha = 0
    bullet.body.gravity.y = -1800

    // Add a touch of tile padding for the collision detection
    bullet.body.tilePadding.x = 50
    bullet.body.tilePadding.y = 1

    bullet.reset(x, y)
    let pointerAngle = this.rootScope.game.physics.arcade.moveToPointer(bullet, this.bulletSpeed)
    bullet.rotation = pointerAngle

    setTimeout(() => {
        bullet.alpha = this.bulletAlpha !== undefined ? this.bulletAlpha : 1
    }, 40)

This is how I collide bullets with the slope ground.

    this.physics.arcade.collide(this.bullets, this.ground,  function(bullet) {
        bullet.kill()
    }, null, this)

Normally I use overlap though.

    this.physics.arcade.overlap(this.bullets, this.ground,  function(bullet) {
        bullet.kill()
    }, null, this)

but this has been happening.

bullets5

Automatically update sprite body polygons

Arcade Physics bodies update their bounds automatically.

Do the same for Arcade Slopes polygons.

See Phaser.Physics.Arcade.Body.updateBounds(). This could be the right internal method to override or extend.

Drop Bower

Bower is used to pull in SAT.js only. Use npm. โœŠ

Update npm package

I noticed npm package not update for 3 months.

Hope it will update with new release. Thanks~

Player falling through tiles when moving quickly

For whatever reason I fly up and gravity appears to bring me down through the ground.

It's hard to reproduce but tends to happen repeatedly when I fall very quickly.

screen shot 2016-07-04 at 12 20 17 am

http://www.youtube.com/watch?v=F_SRvUVgpWo

I tried adding the below code but to no avail:

//  We need to enable physics on the player
this.physics.arcade.enable(this.player)
this.player.body.setSize(GameConsts.PLAYER_BODY_WIDTH, GameConsts.PLAYER_BODY_HEIGHT, 105, 10)
this.game.slopes.enable(this.player)

// Add a touch of tile padding for the collision detection
this.player.body.tilePadding.x = 10
this.player.body.tilePadding.y = 10

Circular physics body support

Recent versions of Phaser have seen an implementation circular physics bodies for collision with other sprites, but not tilemaps.

SAT.js can resolve circle vs. polygon collisions, so this seems like a fitting new feature for the plugin.

Update typescript definitions for 0.2.0

The Typescript definitions are out of date after the new features have been added.

@IkonOne, would you be interested in making a PR for this?

I can totally tackle it myself but I have no dev environment for Typescript (never used it), so I couldn't verify their correctness.

New demo UI

Update the the demo page to use Bootstrap and datgui.

Add some consistent navigation between the demo and the tileset generator.

Question: How to prevent slipping or sliding on slopes

Note: Question / answer session transcribed on to an issue to help out others with a similar problem.

============================================

Hi,

What parameters do I need to set to prevent the player sprite from sliding down a slope. In my code, even the slightest of slops causes the player to slide down to flat ground. In your demo code, the player sprite slides of a bit but eventually stops, even on 45 degree slopes. I have tried to use the same physics params as per your demo but I still get the slipping effect.

What should I do to prevent slipping? There may be a answer but I'm new to using Phaser and my last game programming stint was with XNA.

Thanks & Regards
Colin

============================================

Hey Colin,

The solution in the demo is to use X-axis drag on the body, as well as the "minimum Y axis" feature that's mentioned in here in the readme.

This feature separates collision bodies on the Y axis only where appropriate, so that the sliding does not occur.

The sliding is actually caused by the separating axis theorem, which looks for the shortest possible way for one shape to no longer intersect another. I looked into a solution for this for early versions of the plugin and settled on this "minimum Y axis" approach that I found somewhere buried in a forum.

A second solution that I've been using in a game I'm developing is to simply turn off gravity for the player body whenever it is touching anything beneath itself (player.body.touching.down).

I hope this helps, please feel free to get in touch if you have any more trouble with this. It pestered me for a while and it was important, for me, that the plugin could at least attempt to help with this problem.

Cheers,
Chris

============================================

Hi Chris,

Thanks for your response. I had already set the preferY for SAT testing and also had body drag set as per the demo's setting. What eventually helped was setting the friction coefficients to 0.2 on the sprite's body. The 0.2 setting was just right to have the player slow down to a stop on 0.5 tangent slopes but still slide down gradually on 1.0 tangent (45 degree) slopes.

I also had a problem with the player loosing momentum when walking on the slopes, but I solved this using high acceleration values (3000) coupled with a relatively ow max velocity (250) on the horizontal axis. This resulted in a responsive sprite that can climb slopes steadily with only a slight slowdown.

Once again, thanks a lot! You've been very helpful.

Cheers! :)
Colin

============================================

Hey Colin,

I'm glad to hear it! That's very similar to what I ended up doing in the demo too, tweaking values until I found the behaviour I needed and landing around there.

Balancing friction, drag, acceleration and max velocity against the gravity applied to the character is the way to go for quite a natural look and feel.

I'm still looking into the best ways for the plugin to provide no struggle when ascending slopes, or explicitly controlling said struggle, but for my current project I've simply been adjusting gravity with quite some success. And, to be fair, such collisions could end up very game specific, so for now I've left it to the user until I can think up something magical (if ever).

Cheers,
Chris

Errors: "Unresolved slope type 'r' / Slope type r not defined", "tilemapLayer.getTileOffsetX is not a function"

I'm trying to set up a basic Phaser CE project with the arcade-slopes plugin. I have a Phaser 3 project where I'm handling sloped platforms with MatterJS, but Arcade has some methods that would be very useful for this project, so I want to compare slope-handling in CE with the plugin to slope-handling in Phaser 3 with Matter.

I'm running the bare-bones Webpack template from the Phaser CE repo and I'm running the project with node through VS Code. I used the provided arcadeslopes tileset and followed the instructions on the main repo page for the plugin for setting up.

I have run into these two issues, and I'm not sure if it's a bug or just me making novice mistakes, LOL. (I've been learning Phaser3 for about half a year, and this is my first time using CE.)

  • "tilemapLayer.getTileOffsetX is not a function" : this error occurs when setting up a collider between the player sprite and the platform. It goes away if I comment out any lines of code related to the plugin.
  • "Unresolved slope type 'r' / Slope type r not defined" : this error occurs with or without the collider, it goes away if I comment out any lines of code related to the plugin.

Here are screenshots of the dev tools console, and you can view the complete source code at this Drive folder.

With plugin-related lines of code commented out
With no collider
With collider
Could you please enlighten me as to what's going wrong here?

Tile collision direction flags

Hi Hexus,

I'm really enjoying you're slopes plugin, its exactly what I needed for my game.

I'm trying to implement jumping through a platform from underneath. I believe normally for a tilemap you can just set the parameter collideDown to false for each tile. Since your plugin uses tilemaps, I've tried doing this but still get collisions from below so I can't jump through. Is there a specific way to turn off down collisions for your slopes plugin or am I doing something wrong? Thanks!

Fix the wasTouching flags

It seems like the wasTouching flags don't propagate between updates correctly. They're always false.

Investigate and fix this.

Arcade Slopes tilesets

Create some original tilesets at different sizes for developers to use, along with a mapping preset (#9).

  • 16px
  • 32px
  • 64px

Sprites flying out a certain distance and then falling

https://streamable.com/fak3

Happens on https://rangersteve.io when shooting. Maybe I should be specifying special slope properties just for bullets?

How I'm shooting the bullets

    let bullet = this.bullets.getFirstDead()
    bullet.body.gravity.y = -GameConsts.BULLET_GRAVITY // 850
    bullet.height = 2
    bullet.width = 40
    bullet.reset(x, y)
    let pointerAngle = this.game.physics.arcade.moveToPointer(bullet, currentWeapon.bulletSpeed) // currentWeapon.bulletSpeed === 2300
    bullet.rotation = pointerAngle

How I'm creating the bullets

    this.bullets = this.game.add.group()
    this.bullets.createMultiple(30, 'bullet')
    this.bullets.setAll('checkWorldBounds', true)
    this.bullets.setAll('outOfBoundsKill', true)

    this.physics.arcade.enable(this.bullets)
    this.game.slopes.enable(this.bullets)
    this.bullets.forEach(function(bullet) {
        bullet.body.height = 15
        bullet.body.width = 15
        bullet.height = 2
        bullet.width = 40

        // Define some shortcuts to some useful objects
        var body = bullet.body

        // Update player body properties
        body.drag.x = GameConsts.SLOPE_FEATURES.dragX
        body.drag.y = GameConsts.SLOPE_FEATURES.dragY
        body.bounce.x = GameConsts.SLOPE_FEATURES.bounceX
        body.bounce.y = GameConsts.SLOPE_FEATURES.bounceY

        // Update player body Arcade Slopes properties
        body.slopes.friction.x = GameConsts.SLOPE_FEATURES.frictionX
        body.slopes.friction.y = GameConsts.SLOPE_FEATURES.frictionY
        body.slopes.preferY    = GameConsts.SLOPE_FEATURES.minimumOffsetY
        body.slopes.pullUp     = GameConsts.SLOPE_FEATURES.pullUp
        body.slopes.pullDown   = GameConsts.SLOPE_FEATURES.pullDown
        body.slopes.pullLeft   = GameConsts.SLOPE_FEATURES.pullLeft
        body.slopes.pullRight  = GameConsts.SLOPE_FEATURES.pullRight
        body.slopes.snapUp     = GameConsts.SLOPE_FEATURES.snapUp
        body.slopes.snapDown   = GameConsts.SLOPE_FEATURES.snapDown
        body.slopes.snapLeft   = GameConsts.SLOPE_FEATURES.snapLeft
        body.slopes.snapRight  = GameConsts.SLOPE_FEATURES.snapRight
    }, this)

GameConsts just in case

// Physics
    MAX_VELOCITY_X: 500,
    MAX_VELOCITY_Y: 1000, // Max velocity before player starts going through the ground.
    BULLET_GRAVITY: 850,

    // Slope Plugin
    SLOPE_FEATURES: {
        acceleration: 1500,
        bounceX: 0,
        bounceY: 0,
        debug: 0,
        dragX: 1000,
        dragY: 100,
        enableGravity: true,
        frictionX: 0,
        frictionY: 0,
        gravity: 1100,
        jump: 450,
        minimumOffsetY: 1,
        pullDown: 0,
        pullLeft: 0,
        pullRight: 0,
        pullUp: 0,
        snapDown: 0,
        snapLeft: 0,
        snapRight: 0,
        snapUp: 0
    },

Improve tunnelling

As per phaserjs/phaser-ce#94 and the road map, improvements can be made to tunnelling issues that can occur with small sprites.

In the linked issue, it looks like the projectiles are only colliding with the tile face and not the entire tile.

The linked issue is caused by heuristics preventing collisions, and because the square tile has no "preferred axis" to separate on, no separation seems to occur. This is rather wrong! Pre v0.3.0, this could be solved by improving heuristics or simply not using them for square tiles.

In the case of the half tiles in the GIF below, the separation is responding correctly but without invoking collision callback, which is wrong.


There are two issues here that will be addressed by planned features in the v0.3.0 roadmap:

  • Custom SAT implementation that can ignore some axes
  • Raycasting to avoid tunnelling

For 0.2.0 we want to at least make sure that the collisions and their callbacks are responding correctly; even if no separation occurs, it's still a collision the user could need to know about.

Deciding the response vector in these situations is tricky.

Full-block tile in arcadeslopes not registering for collision

I'm currently using the Arcade Slopes tileset (32px) provided in this repository. However, the tileset is showing some bizarre behavior; in particular, the first tile (full-block) is inconsistent in being collide-able.

Below is an example in Tiled of using the tileset in a map:

img1

However, when seen in the actual game, the selection of full-blocks on the top-right is not registered for collisions at all. Also, while the half-blocks are registered for collision when used in the house, it does not register for collision when placed next to a full-block (as seen in the stack of logs next to the house.)

img2

However, the tiles on the stack of logs WILL register for collision if there are other tiles directly adjacent to it. Below is an example in Tiled where I place more vertical half-blocks near the logs:

img3

In this case, when seen in the game, the collisions work as intended (although the tiles in the top-right are still not registered):

img4

I'm not sure if this is a bug, or if there is a specific criteria that needs to be required for full-blocks (and other blocks) to be registered for collision. Below is the relevant code for your reference. Here's the actual link to the repository if more information is needed. I'm also using Phaser CE (v2.8.4).

Game State:

preload() {
    this.game.load.image('sprite', 'assets/sprites/sprite.png');
    this.game.load.spritesheet('arcade-slopes-32', 'assets/map/arcade-slopes-32.png', 32, 32);
    this.game.load.tilemap('map', 'assets/map/example_map.json', null, Phaser.Tilemap.TILED_JSON);
    this.game.load.spritesheet('tileset', 'assets/map/tilesheet.png', 32, 32);
}

create() {
    ...
    const map = this.game.add.tilemap('map');
    map.addTilesetImage('tilesheet', 'tileset');
    map.addTilesetImage('collisions', 'arcade-slopes-32');
    for (let i = 0; i < map.layers.length; i++) {
      if (map.layers[i].name !== 'collisions') {
        map.createLayer(i);
      }
    }
    this.collisionLayer = map.createLayer('collisions');
    map.setCollisionBetween(0, 34, true, this.collisionsLayer);
    this.game.slopes.convertTilemapLayer(this.collisionLayer, 'arcadeslopes');
    this.collisionLayer.debug = true;
}

update() {
    ...
    if (player && player.sprite) {
      this.game.physics.arcade.collide(player.sprite, this.collisionLayer, () => {
        console.log("Hey");
      });
    }
  }
}

Curved slopes

I'd like to suggest the introduction of additional curved slopes like the ones below:

image

I understand that collision bodies for the sloped tiles are generated from polygons which are made of straight edges, but I think with some interpolation, curved slopes can also be generated programmatically.

The formula for the curved part of the 4 tiles above are:

  1. y = w - c(x)
  2. y = w - c(x + w)
  3. y = c(2w - x)
  4. y = c(w-x)

where c(x) = x^2 / 4w
and w is the width of the tile (e.g. 16, 32, 64, 128 etc.)
Note: I'm assuming that the Y axis points downwards, as per normal display convention.

When generating the curved slope, x would be sweeped from 0 to w by a step of 1 and y would be computed accordingly. For practical purposes, x can be incremented by a larger step, e.g. by w / 4 to reduce the number of sides.

An additional point for tile 1 and 4, or two points for 2 and 3, would need to be generated for the lower corner(s).

I can give you the formulas for the 4 tiles going down right, but as you might imagine, they are simple variants of tiles 1 to 4.

Notice how 2 and 3 have 45 degree slopes at one end, which makes it possible to combine them with straight 45 degree slopes.

Flatter versions (1/2 height) can be generated for transitioning on to straight 22.5 degree slopes as well, since their edge would end at halfway up the second tile with a tangent corresponding to the 22.5 slopes, so the second 22.5 straight slope can be placed next to it for a smooth transition.

These could be also extended to curved ceiling tiles, but they're not really that useful.

I could try extending your library myself, but I'm not sure I understand the rest of your code!

What are your thoughts on this?

Automatically set colliding tiles for Tilemaps

Having to work out the numbers for map.setCollisionBetween() is a bit of a pain, so it would be great if the plugin could set this on the map objects itself. It makes the API even friendlier.

I've also noticed that internal edges on tile objects (collideUp, etc) don't get flagged correctly if map.setCollisionBetween() is called after creating layers. This should be looked into.

Related to #43 and #49.

Mapping shortcuts

  • Ninja Physics debug tileset
  • Arcade Slopes tileset
  • Tile properties (tile.properties.type)

Ninja physics mapping for 64px+

Somehow I've only just realised that the mapping for 64px+ ninja physics debug tilesets are different from the 32px layout!

Define a ninja2 or ninja64 mapping.

Prevent internal edge collisions without heuristics

The heuristics are pretty painful now, when it comes to maintainability and reliability. It's time to use SAT.js more wisely.

This is part of the 0.3.0 roadmap, and the item looks like this:

  • Custom SAT.js implementation that can prevent internal edge collisions (like this)

http://www.wildbunny.co.uk/blog/2012/10/31/2d-polygonal-collision-detection-and-internal-edges/comment-page-1/#comment-1978

The discussion here proposes ignoring collisions that occur with internal edges, which is a nice solution, and in fact what the heuristics do already.

After some experimentation in the ignormals branch (hah) at the same time as tinkering with SAT.js, this turns out to work exactly the same way, except it resurfaces the issue with skipped collisions for small and fast projects between tile seams (#38).

The direction I want to take this is using SAT.js to first determine if there is any collision, and instead of using the shortest separation that it gives back, use the shortest separation that isn't an ignored axis, which are indeed now flagged as part of each tile's polygon edge normals.

I tried to do this by just skipping flagged normals in SAT.js to let it fall back to the smallest non-ignored normal, but the results were identical, which means either:

  • SAT.js has trouble with tiny polygons
  • SAT.js is doing something that I'm not aware of
  • My understanding of SAT.js or SAT is... flawed

This can probably be achieved outside of SAT.js with a custom testPolygonPolygon() function.

Body slopes variable.

The slopes variable added to the Body class is a dynamic object. These are unusable in typescript as they will throw errors when trying to access their member variables(unless you use ['array'] access). This commit I created some classes in the typescript definition so that the variables are properly accessible: IkonOne@df06dc6

The added classes are BodySlopes and BodySlopesSat. I think that an approach like this is ok for now. If you agree with this approach, I can convert the objects in the JS code to classes as well as you mentioned the possibility of here: https://github.com/hexus/phaser-arcade-slopes/blob/master/src/ArcadeSlopes/Facade.js#L87

The two classes needed could possibly go in a new file called BodyMods.js or something.

Also, since the sat variable is only used to store the responses, maybe simply having a collision or response variable might be a better fit.

Offset tilemap layer support

When a tilemap layer's fixedToCamera property is false, Arcade Physics works with offset tile maps, and everything looks okay as long as the camera isn't moved.

Support this in Arcade Slopes by passing through the tilemap layer to collision solvers.


A note on Phaser's tilemap layers:

Phaser's TilemapLayer implementation does thoroughly contradicts the fixedToCamera property with lines like these in its postUpdate() and _render* methods:

if (this.fixedToCamera)
{
	this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
	this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
}

this._scrollX = this.game.camera.view.x * this.scrollFactorX / this.scale.x;
this._scrollY = this.game.camera.view.y * this.scrollFactorY / this.scale.y;

So no matter where the TilemapLayer sprite is positioned, it will always scroll tiles with the camera. There is no way to override this without changing these methods.

This can be fixed by introducing a separation between the TilemapLayer's sprite position and its scrolling position, which will also help to fix mismatched collision as soon as the camera moves.

Wiki for tile slope types

Create a wiki page that lists all the tile slope types and how to create your own mappings for custom tile sets.

Debug rendering

Implement the rendering of debug geometry for:

  • Tile polygons
  • Tile face properties
  • Collision vectors (a little more tricky)
  • Broad-phase tiles

The crossed out tasks will be saved for a later version.

Phaser 3

Hello,
planned a update to phaser 3?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.