In the Niantic Studio Game Mechanics Basics Workshop, we learn how to make coins for the player to collect. How do I make another type of collectible? Like if I wanted to have bronze, silver and gold coins, how would I program this? I thought if I just made a new object, copied the coin code and changed “coin” to something else, that would make a new collectible, but I keep getting errors no matter where I paste the code.
Here is the code I’ve been trying to change inside the character controller code. I tried pasting the code for the new collectible underneath this, but that gives me errors. How can I add new code to the existing code without getting errors? Also what programing language is this? Or is it unique to Niantic Studio?
// Handle start of a collision
const handleCollisionStart = (e) => {
// Check if the entity involved in the collision is a Coin
if (Coin.has(world, e.data.other)) {
// Remove this coin from the world
world.deleteEntity(e.data.other)
// Trigger the global ‘coinCollect’ event
world.events.dispatch(world.events.globalId, ‘coinCollect’)
// As this is an event-only collision, stop execution of physics collisions
return
}
// If it was not a coin that we collided with, continue with physics collision logic
const data = dataAttribute.cursor(eid)
data.collisionCount++
updateGroundedState()
}