How to make something get picked up when touched it

plz help me with it i looked at other disscusions it did not help

Hi @XZAYDEN_MARTINEZ and welcome! There are several ways to do this. Did you already try to use a trigger?

https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

https://developer.playcanvas.com/en/user-manual/physics/trigger-volumes/

hy Albertos i have tried but i don’t understand it

also can you help me with random world genration here is my leangh i don’tknow what i am doing wrong thanks XZAYDEN_MARTINEZ

oh yeah here is the link https://playcanvas.com/editor/scene/1281590 thanks xzayden

Which entity in your project do you want to pick up? This entity need a collision component and a script component.

iron stick

Create a new script with the name ‘trigger’ and replace the code with the code below. Save the script. Add the script to the script component of the entity. Launch the game to see if it does something.

var Trigger = pc.createScript('trigger');

// initialize code called once per entity
Trigger.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};

Trigger.prototype.onTriggerEnter = function(entity) {
    if (entity.name ===  'Player') {
        this.entity.reparent(entity);
    }
};

Cannot read properties of undefined (reading ‘on’) that is what its saying

it works by it appers in the sky


also it does not move with the camrea

You didn’t create a new script with the name ‘trigger’, so the actual script name is conflicting with the script name in your code.

Probably it takes over the height of your player because we made it a child of your player, but I’m not sure.

I think you mean it does not rotate with the camera? Maybe you can make it a child of your camera instead of your player.

1 Like