[Solved]Object not appearing

I’m still learning how to code bit by bit, but this got me pretty confused. I tried to watch vids about object picking but I can’t really wrap my head around it.

I wanted to try out making the “press [E] to interact” kind of thing when the player is near an interactable object. It worked fine at first, got the [E] thing to appear above the flowers.

Tho, the problem starts appearing when I try to copy and paste the flowers next to each other. The [E] only appears on the first flower the player walked by and not the rest. The [E] also disappears only after the player doesn’t touch any more flowers.
The player can still pick up the flowers nearby that doesn’t have an [E] on them, which is also kind of a problem since it can pick up multiple flowers at once instead of just one that’s attached with the [E] thing.

Idk if that makes sense so here’s a gif of it.


I tried to code it in other ways that I could think of, but the problems are still the same. Tho, I did try to remove the trigger once condition and got a different issue instead.

I feel like I might’ve overlooked the solution, but any help/explanation would be appreciated! ;;

It took me longer to figure out the best way to do this that I’d like to admit. I believe this is good.
I added a pick nearest lily because when I made an example. There were 2 lily objects within 75 px.
I checked the last distance to be distance from pressE instead of lily. There is only 1 pressE but multiple lily object. So, there was always at least 1 lily object that was > 75 px away from the player.

The issue with the trigger once is the flowers are close enough that the player is probably within 75px of multiple flowers, so the state doesn’t get a chance to go from true to false and back to true.

2 Likes

The trigger once only actions an event if the condition wasn’t true previously, and is true now. Having it by itself is the best move, it is better with other conditions.

Also, that last event will work on all pressE objects, not just the one linked to the lily objects that are over 75 pixels from the player.

My suggestion would be to do the following:

  1. remove all the trigger once conditions.
  2. to the first event, add the inverted condition 'PressE is in collision with lily". This will ensure it only works on lily objects that don’t have the PressE object touching them.
  3. Move the e key is pressed event one level to the left, and add the condition 'PressE is in collision with lily".
  4. to the second to last event (the inverted distance check), add the condition 'PressE is in collision with lily".

[edit]
@Keith_1357 replied while I was in the middle of composing my response. @sevendies , you have a couple of solutions to try out :smiley:

2 Likes

I actually had it like a few of MrMen’s ideas. I was trying to keep it close to the current version. All of the ideas are good. Use what works best or fits your preferences.

@Keith_1357 @MrMen Thank you so much for answering! It all makes a lot of sense now! I tried combining both of your suggestions and I think they work nicely!

I also kinda managed to find a way to work around this issue by deleting and creating the same object in a single event. I don’t know why exactly, but I guess it just works?

Thank you again! I can now eat flowers digitally

1 Like