How to enable something after interacting with something else

i want to be able to “pick up guns” of the ground, and i want the player to not be able to enable it until he touches the weapon on the ground, after he touches the thing on the ground, he is free to enable it whenever he wants
and then maybe disable everything after teleporting, but i might be able to do that by switching scenes

hello?

Hi @Thebosser_24! For me it’s a little hard to understand what you try to achieve.

so like i have a gun on the ground, and i walk on it, it would let me switch to it,
so the wapon switch script is composed of

       if (this.app.keyboard.isPressed(pc.KEY_3)){
this.mini.enabled = false;
this.sa.enabled = false;
this.hands.enabled = false;
this.ss.enabled = false;
this.shotgun.enabled = true;
this.musket.enabled = false;

but i want for me be not able to switch to a weapon, until i touch the corresponding one on the ground, so it looks like i picked it up
and then after i step on the weapon, i can enable/disable it all i want

Do you have for every weapon only one in your scene?

1 Like

yes i do

In that case, if the player press the key, I would check the distance between the player and the objects and enable the object that is close enough.

https://developer.playcanvas.com/api/pc.Vec3.html#distance

1 Like

and then can i make it to where i can enable it/ disable it after i am close enough, and i can walk really far and freely enable/ disable it

Maybe the project of @Tirk182 can help you with it. You can check the topic below.

2 Likes