Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by SpaceHorse

player.standing is working in standard Impact engine.
Do you know how to implement it when i use box2d ?

i mean there is
## handleMovementTrace: function( res ) {this.standing = false; ...} ##
in default ImpactJS. So, how to do the same in box2d? cause it has it's own collision model

1 decade ago by dominic

From the Box2D Plugin Thread:

update: function() {
    // Iterate over all contact edges for this body. m_contactList is 
    // a linked list, not an array, hence the "funny" way of iterating 
    // over it
    for( var edge = this.body.m_contactList; edge; edge = edge.next ) {
        
        // Get the normal vector for this contact
        var normal = edge.contact.m_manifold.normal;
        
        // If the normal vector for this contact is pointing upwards
        // (y is less than 0), then this body is "standing" on something
        if( normal.y < 0 ) {
            console.log( 'standing!' );
        }                
    }
    
    …
}

1 decade ago by SpaceHorse

wow, man. thank you a lot!!

1 decade ago by tom

I think there's a bug in Box2D, not sure, but basically it goes like this:

If you are up against a wall, (say, to your sprite's right) the normal vector will rapidly toggle between:

(0, -1) - normal vector pointing up out of the floor

and

(-1, 0) - normal vector pointing out of the wall

Additionally, when standing on another Box2d object, the normal vector is (0, 1), which seems wrong to me.

If I figure out a solution I'll update this thread. Dominic's code is a great start but I'm finding a few edge cases where the physics engine is reporting strange data that needs to be handled.

1 decade ago by Neeko

The code here appears to be a bit outdated when using the latest version of the Box2d plugin. This thread being two years old, I'm sure it was bound to happen ;)

The following line

var normal = edge.contact.m_manifold.normal;

There isn't a normal property of b2Manifold. What should we be checking against instead?

I'm using the m_localPlaneNormal property, but the results of the contact edges aren't consistent; normal.y returns 1 when my entity is clearly standing on the collision map. This seems to relate to what tom reported. Curious is anyone figured it out?

1 decade ago by AzZzOne

Hi all!

I'm using the following code to define player standing :

 for (var edge = this.body.m_contactList;
                                edge; edge = edge.next) {
                            if (!edge.contact.IsTouching()) {
                                continue;
                            }
                            var normal = edge.contact.m_manifold.m_localPlaneNormal;
                            if (normal.y < 0) {
                                return true;
                            }
                        }
                        return false;
                    }

I have a level with crates. When i jump on the one of the crates player.stading = true but when i turn the crate on the other side ( during the game) and jump on it once more i get player.standing = false .

Would appreciate any help!
Page 1 of 1
« first « previous next › last »