Collisions with walls

I have been trying to make a entity stop when it collides with another. What code would i put in the if statement.

var Collider = pc.createScript('collider');

// initialize code called once per entity
Collider.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};

Collider.prototype.onCollisionStart = function (result) {
    if (result.other.rigidbody) {
        ...
    }
};

Like so?

If you want it to stop in all directions, then put this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;

1 Like

Add

this.entity.rigidbody.angularVelocity = pc.Vec3.ZERO; 

To @DevPlex01’s code as well.

1 Like