[SOLVED] Collision detection script not working

The game I am working on is going to be a Metroidvania, so Item collecting is necessary for gameplay(one item is currently enabled by default(c), but will be disabled later until you collect its item). I added a collect item script, and 2 entities, one that checks what items you have and another that will give you the items using the same script. But the collision on the item is not reacting to the player,(I elongated the collision box across the z access since the player moves up the z-axis by one while dashing and moves back after they finish dashing(so you can dash over pits), and I wanted the player to collect it in both states) can anyone help me figure out what is wrong with the script/collision. I added a console.error(so I can see it because I cannot see the browser console) script to play if the player successfully collects it, but I don’t see that either.

Link to script: PlayCanvas | HTML5 Game Engine

Link to the part of the project I am testing this with so far: PlayCanvas | HTML5 Game Engine

Hi @Linkplayer!

Your collision is working, but this.item is undefined. That’s because this is missing in your collision event. If you replace line 6 of your itemCollect script with the line below, the problem is solved.

this.entity.collision.on('triggerenter', this.collectItem, this);

I did define this.item

this.item is an attribute that I added to the script in line 2.

Would adding , this) to the collision detection fix it though?

That’s correct, but it’s not working because of your event.

Yes, I tested it.

well, the collision detection works now, but now I need to detect the variable that was changed. The item disappears like it should, but the fired shots stay the basic shots, the Move Quiste script is not detecting the variable, despite working on every other instance I use the same script line

I made a custom error link to the line I need help with: PlayCanvas | HTML5 Game Engine

You are creating the variables in the update function of your script (so every frame). That means they are only available in the update function of that script.

image

You can create variables in the initialize function using this or you can create global variables after the first line of your script (like you do with multiblast and thermaSuit).

so if I try to detect thermalSuit instead of hasThermalSuit it should work?

I don’t know your logic, but I guess instead of using hasThermalSuit you can check if thermalSuit is not zero.

Isn’t thermalSuit a global variable, so should it be able to detect it or something?

As far I have seen yesterday, thermalSuit is a global variable.

I did a few edits, but the laser blast is still not changing to the upgraded one, can you identify why it is not detecting any of the variables?
script that is detecting it: PlayCanvas | HTML5 Game Engine

nvm I just got it to work

thx for the help

2 Likes