Comments (5)
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.
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.
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.
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.
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)
- this.game.tilemap is undefined
- Support for Phaser 3? HOT 1
- Thank you for your work! HOT 1
- "Tile Layer Format" matters! HOT 2
- `tilemap.removeTile` etc operations don't modify `plus.tileAnimations` HOT 3
- Scaled Layer Physics HOT 4
- Cannot read property 'properties" of null HOT 7
- cannot read property 'plus' of undefined HOT 3
- Trigger Tile Animation on Region Based Event HOT 2
- Loading tilemap with preloaded json object not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phaser-tilemap-plus.