Collision adds more than 1 to variable even though it should add only 1, how do i fix it? (solved)

so i have this game where if there is a collision between player and a rectangle then it adds 1 to the variable score and modifies the text accordingly, everything works fine if the player collides with the wider side of the rectangle but when it collides with the smaller side, then instead of adding 1 to the variable, it adds a value of more than 1(sometimes 7 sometimes 9 and so on). this disrupts the scoring system of the game. and i also forgot to mention that the blocks are moving on the x axis. any help is appreciated :slight_smile:

Probaste el ejecutar une vez?

yes i tried once while true

Wondering if it might have something to do with your hitbox… how is the hitbox looking?
Another thought, if it’s adding many more collisions than expected then did you do add a “trigger once” condition to see if that helps?

You should use trigger once event with it.
Collision is a continuous function.

i have but i think the problem is that that the player is separated on collision and the block is moving so it happens again and again… lol if u get what im saying XD and thanks for the reply :slightly_smiling_face:

if I understand correctly, you want each rectangle give point only once in lifetime.
if yes, than you should add an object instance variable to the rectangles. for example : “scored”. and when the collision happens with trigger once, you check the variable’s state. if its “no”, than do the actions, give the score AND set this variable to “yes”. if you do, each square will only be able to score once

I’m not sure if this is what you intend, but you can add a “switch” variable. If the value is 0 and there is a collision, change it to 1 and add 1 to the score.
Then change the value of the switch to 0 in the next frame only if there is no collision at all.

thanks for the tips, although the text variable didnt work but i just used a number instead and it worked great, thanks for the idea boss

yeah thanks i followed what u said although i didnt need to reset the value since i was using an instance variable, thanks for all the help brother

of course it work with text variables too. thats why I advised. because I use this method in my game with text variables and work perfectly.
but anyway, the point is that the problem is solved.

1 Like