Trigger an object to appear when you collect a certain item

Hello, this is my first time using Playcanvas and been struggling with understanding coding lately. I’m making a simple 2D game where my character collects items to achieving the game’s objectives. I plan to trigger an object to appear when you collect a certain item, but I don’t know how to spawn the item when a certain item’s collected. How does the coding work? Thank you :"<

1 Like

Hello @amara1105 and welcome!

I would take a look at this example. It takes you through on how to complete a game with PlayCanvas. I believe it covers the game mechanic you’re describing!

https://developer.playcanvas.com/en/tutorials/crash-course/

Good luck!

4 Likes

Hello, thanks for the welcome! Thank you so much for responding to my concern! Yes, this seem to be the kind of game mechanic I’m looking for! Is it also possible to spawning maybe 2 more items and when it gets collected, 2 appears? Thanks again! :slight_smile:

Yes, of course. Once you get a good grasp of the game mechanics you can alter them as you like!

1 Like

Hello! I just came back from the crash course tutorial and it’s pretty overwhelming but I understand it! Though, is there a simplified version of the code without the timer and specifically focuses on triggering items only? Thanks again! :smiley:

1 Like

Really glad you understood it! Maybe you will need to study a simpler project, like this tutorial: Collision and Triggers | Learn PlayCanvas

Once you understand this, you will need to figure out how to spawn items in the right event :wink:

2 Likes

Hi, Ms. Christina! It’s me again. I was able to do simple collision recently (like, collecting an item) but somehow I still struggle to enhancing my mechanic of spawning items. I read about this Programmatically Creating Entities | Learn PlayCanvas and it’s about creating entities but the tutorial is pretty overwhelming in my basic level. Maybe a simplified version of spawning objects in 2D can do since I get confused with 3D. Thank you for being patient with me :"(

Hey @amara1105 ,

Here is a simple project I’ve done in the past, it’s a simple cube spawner. Pretty simple and straight forward. Take a look here: PlayCanvas 3D HTML5 Game Engine

Good luck!

1 Like

@Christina , the project is blank on master ? :sweat_smile:

Ah, yeah, actually you need to press space to start spawn cubes :innocent:

The code is inside create-entities.js

But there are no assets/scripts :sweat_smile:

Ahm… That’s weird I just opened it and there was an asset folder with scripts. :thinking: There was no branch created as well. I just stepped outside let me take a look once a get back.

Oh, you were right! I had a branch and totally forgot about it. :woman_facepalming:t4: I will switch to master once I get back. Sorry about that!

It is now fixed.

Here is the link again: PlayCanvas 3D HTML5 Game Engine

3 Likes

This is amazing! Fully understood it now, thank you so much Ms.Christina!! I really appreciate this :heart_eyes: :sob:

2 Likes