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!
problem with player colliding with objects (for loop)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
problem with player colliding with objects (for loop)
- Attachments
-
- test0.love
- (12.5 KiB) Downloaded 125 times
Re: problem with player colliding with objects (for loop)
Something very similar happened to someone very recently.
What happens is that when checking the collision with the first object, 'hero.observes' is made true, but the loop continues and when checking the collision with the second object, 'hero.observes' is overwritten and set to false.
You need to set 'hero.observes' to false before the loop, not inside.
What happens is that when checking the collision with the first object, 'hero.observes' is made true, but the loop continues and when checking the collision with the second object, 'hero.observes' is overwritten and set to false.
You need to set 'hero.observes' to false before the loop, not inside.
Re: problem with player colliding with objects (for loop)
thank you for replying! I swear I did use the forum search, but I haven't found any recent thread with such question. sorry.
I did what you suggested and it helped. thanks a lot.
I did what you suggested and it helped. thanks a lot.
Who is online
Users browsing this forum: No registered users and 1 guest