Git Product home page Git Product logo

Comments (5)

RenaudRohlinger avatar RenaudRohlinger commented on May 12, 2024

Furthermore, could it be possible to update the body physics properties like sprite.body.blocked and sprite.body.touching based on your extension ?

from phaser-tilemap-plus.

colinvella avatar colinvella commented on May 12, 2024

Hi,

I think the solution would be for the plugin to set the blocked and touching properties as you suggested. As a temporary measure, did you try to set them manually based on contactNormal?

The issue can also be noticed in the demo in fact. I'll find a work around as soon as I can and will update the package.

from phaser-tilemap-plus.

RenaudRohlinger avatar RenaudRohlinger commented on May 12, 2024

I added a method to update the flags in your Physics.js file (called in collideWidth)

    updateFlags (sprite, contactNormal) {
        const body = sprite.body;

        body.touching.up    = body.touching.up    || contactNormal.y > 0;
        body.touching.down  = body.touching.down  || contactNormal.y < 0;
        body.touching.left  = body.touching.left  || contactNormal.x > 0;
        body.touching.right = body.touching.right || contactNormal.x < 0;
        body.touching.none  = !body.touching.up && !body.touching.down && !body.touching.left && !body.touching.right;

        // Set the blocked values
        body.blocked.up    = body.blocked.up    || contactNormal.x === 0 && contactNormal.y > 0;
        body.blocked.down  = body.blocked.down  || contactNormal.x === 0 && contactNormal.y < 0;
        body.blocked.left  = body.blocked.left  || contactNormal.y === 0 && contactNormal.x > 0;
        body.blocked.right = body.blocked.right || contactNormal.y === 0 && contactNormal.x < 0;
    }

It works fine but the main problem is still that the contactNormal.y === 0 when contactNormal.x === - 1 || 1

As Leonardo DiCaprio would say in the movie Inception :
"We need to go deeper"

[Update] :
After some research I found that disabling the update of the body.velocity in the collideWidth method will prevent this issue. So basically if the sprite.body is blocked on the right and bottom, your algorithm will set a negative velocity.y which will update body.blocked.down to false and then on the next update set it to true with a new velocity.y --> my issue

from phaser-tilemap-plus.

colinvella avatar colinvella commented on May 12, 2024

One of the challenges with dealing with this issue is that the contact normal and penetration vector are accumulated so that if you're walking into a wall, rather than getting these two vector quantities per each surface (floor and wall), you get them combined. That is, for the contact normal, you get a diagonal vector pointing away from both the floor and wall (think of a vector jutting from the corner when floor meets wall and pointing towards your sprite).

I think I'll need to alter the contact resolution code to yield contact normals and penetration vectors for each surface that the sprite is in contact with. For the sake of back compatibility, the accumulated quantities will still be retained. In this manner, it will be possible to check if the sprite is touching a wall that is impeding walking and disable the animation accordingly.

from phaser-tilemap-plus.

colinvella avatar colinvella commented on May 12, 2024

The physics module now sets the blocking flags accordingly. Touching is not set because this is for sprite to sprite collisions only. Besides an overall contact normal,an array of all contact normals from all surface collisions is attached to the body. This allows for vertical or near vertical wall testing so that walk animations may be disabled where applicable.

from phaser-tilemap-plus.

Related Issues (11)

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.