problem with player colliding with objects (for loop)
Posted: Thu Jul 11, 2019 12:26 am
hello, I am very new to gamedev so sorry for asking rather silly questions (sorry for my bad english as well).
so, recently I've started working on a little project and ran into a problem which I can't understand. I've created a simple "game" to recreate this thing (I'll attach it in my post). now, let me explain what I'm facing:
I have, say, two objects on the scene. they have a variable printed above both of them to show if the player collides with them (returns true or false). I also have the same-ish thing for the player (if a certain variable is true, the player will say his line). there's a "for" loop going through the objects' table, checking if the object collides with hero (I use some copypasted code for collision check).
the problem is that, when the player collides with either first or second object, this object's variable becomes true/false depending on the player's position (this part is working correctly), but the player himself only speaks when colliding with the second object. I assume that the loop somehow doesn't work with player's table variables correctly and uses only the second (I guess, the last in table) object's coordinates.
please check my code, I've ran out of ideas. thanks!
so, recently I've started working on a little project and ran into a problem which I can't understand. I've created a simple "game" to recreate this thing (I'll attach it in my post). now, let me explain what I'm facing:
I have, say, two objects on the scene. they have a variable printed above both of them to show if the player collides with them (returns true or false). I also have the same-ish thing for the player (if a certain variable is true, the player will say his line). there's a "for" loop going through the objects' table, checking if the object collides with hero (I use some copypasted code for collision check).
the problem is that, when the player collides with either first or second object, this object's variable becomes true/false depending on the player's position (this part is working correctly), but the player himself only speaks when colliding with the second object. I assume that the loop somehow doesn't work with player's table variables correctly and uses only the second (I guess, the last in table) object's coordinates.
please check my code, I've ran out of ideas. thanks!