How to make an object that destroys only certain objects when they pass through?


#1

I want to know how I would basically make the Fizzler from Portal. (It destroys certain objects when they go through.)


#2

Hi.
All you need is add masks; colllision groups to the rigidbody … https://launch.playcanvas.com/583817?debug=true


#3

I don’t exactly understand what you mean. That doesn’t seem like it would destroy objects


#4

https://playcanvas.com/editor/scene/583817


#5

You could make a script for entities with a rigid body to destroy themselves when collapsing. Something similar to this: … prototype.update; … onCollision this.entity.enabled = false;


#6

Your script kind of breaks my entire game.


#7

So, I tried making my own script for this. And it does absolutely nothing.


// initialize code called once per entity
Fizzle.prototype.initialize = function() {
    
};

Fizzle.prototype.fizzle = function(result) {
    entity.rigidbody.applyTorque(0, 10, 0);
    entity.collision.enable();
    
    
};

// swap method called for script hot-reloading
// inherit your script state here
// Fizzle.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/```


___________________________________________________________________
var FizzlerCheck = pc.createScript('fizzlerCheck');

// initialize code called once per entity
FizzlerCheck.prototype.initialize = function() {
    
};

FizzlerCheck.prototype.onTriggerEnter = function (otherEntity) {
    // it is not teleportable
    if (result.other.rigidbody)
        if (otherEntity.script.fizzle)
        return;
    
    otherEntity.script.fizzler_check.fizzle(this.entity, this.target);
};

    

// swap method called for script hot-reloading
// inherit your script state here
// FizzlerCheck.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/```

#8

What might be easier is to use the Entity tags. For example, the trigger can check the tags of the entities that pass through and if they match ‘power-up’ for example, they get destroyed by the trigger.