+1 vote

I Have an Island Made of Sand in the middle of the ocean. I want the Player to queue_free When it walks of the island OR one of the Platforms you are able to build in the Game. Thats why i cant just have collisionshapes around it, I need to check when the player leaves a collisionshapes. Thats why it's such a huge problem. I thought i figured it out but then it the code activated when i Left the Sand and stood on the platforms, So i stopped using The area exited signal. I have tried every solotion i can think of and i just can't figure it out, for some reason when i Choose to print when im out of the water like this

if area.name == "Sand":
   print("True")
else:
   print("False")

And i stand OUTSIDE of the island but still quite close for some reason it Prints out both True and False. Right now this engine makes now sense to me. There is not a single collision shape or object at that place and the collision for the player is intentionally smaller than the player. SOMEONE Please EXPLAIN

Godot version 3.2.1
in Engine by (47 points)
edited by

Is there a specific reason you are using 3.2.1? I'd advise you to update to newest version asap.

Back to your problem. Why not make water hot? I mean, instead checking whether player walks off the platform or island why not give your water an area that if player touches water, he queue_free()?

1 Answer

0 votes

Explain why it prints true and false at the same time ?
But you never specified where and what You check in this code. Is it checked every frame in physics(process) or only onplayercollision ? Is it checked in signal or overlapping_areas ??

Depending on the answer - either collision shapes are jittering on the borders, or ( more propable ) your players is colliding with more than one thing at a time.

Logic is simple. You said it : "I want player to queue free when he is away from the island OR away of the platforms ". But this is not true. You want player to queue free when he is away from BOTH platforms AND island. SO You need to write it in code - if player is not touching sand AND he is not touching platform - queue free. You can use enter and exit signals to create boolean values like ( inonsand = true, isonplatofrm = false ). You can also check players collisions every frame, asking for overlapping areas.

by (2,394 points)

Thanks Alot i will try But i swear there is not a single other collision shape touching the island in the editor. But i have found the problem. If i hide every element in the way and run the game it spawns the player Twice, with the second one right next to the first, and it appears to be only when i run the game not in the editor. Even if its just a visual glitch it is this thing that is doing it and i dont know why

My godot version is specified as 3.2.1 but too be honest im not really sure

i found the problem. Something to do with old Autoload tests in the player its off the topic but please can you help me with the code. i tried the boolean values as well as signals mixed with func _process detection and i think im on the right track i just dont want to sit here for 6 weeks until i find a solution thats Complicated Unnesecary and takes up space so please if you dont mind cut to the chase and explain a little better

I would go for sollution, that is not the simplest, but nicely optimized.

Introduce two variables in your menager script and make setget for them :

var onsand = true setget checksand
var onplatform = true setget checkplatform

next define both setter functions :

checksand(value):
      onsand = value
      checkvictory()



checkplatform(value):
          onplatform = value
          checkvictory()

Next define checkvictory conditions :

checkvictory() :
     if onplatform == false and onsand == false :
              player.queue_free()

Next take your connected signals functions, that you propably named "onplatform/sandarea_exit/enter" or something, and insert code there :

Player.onsand ( or onplatform ) = true ( or false )
Most important thing here, is that if its player himself that is connected to those signals, than You must refer to those values using SELF keyword ( like self.onplatform), otherwise setter functions will not pick up any change. 

So I think that is it. I hope your player is not jumping, because he will be queued free when on air with this code :P. DOn't worry, if You have jump in your game just do the same thing with "onair" "aircheck" and in checkvictory add line " and onair == false "

I get What youre thinking. I had This idéa originally aswell just more bulky obviously. but theres a problem. theres more than ONE platform and whenever i move between two its gonna send out a signal for BOTH body entered and body exit. so for a split second its gonna think im not touching anything and register it. But while writing this comment i think i might have found a solotion. Il add a timer with a delay of 0.1 seconds to start when i leave the platform and if the body entered has not fired when it runs out im in the water.

il edit this comment if it works or not once ive tried it.

it didnt't, dont know what i was thinking

I just thought of an easier sollution. Are your platforms on the island itself ? If so, create a new area with collision shape around whole island, that will cover both sand and platforms. Collision shape will detect movement out and in, but will not stop movement of player. With this you will not need any boolean values, just one area exited signal. You can do the same for water, if it is supposed to kill player - just make large area with collision shape covering all water.

https://www.mediafire.com/view/iuebqrvgrrh28xa/Game.png/file

its a 2D topdown, The platforms are not on the island originally instead theres a game meachanic that lets you place down platforms in the game. and you cant place them on the island itself. thats why i cant just have a bigol collisionshape over all water. Im very sorry if i explained my problem a little bad

Solved it. Changed the platform placing sytem so it instead of instancing a scene just uses the tilemap to set a tile looking like the platform. then all i needed to do was match my player position and que it free/teleport it back to start whenever its not touching tile number 0 or 1. i don't need youre help anymore but i apreciate you trying to help me and you did make the process before i found this solution a little shorter as well as teach me some new thinks about godot. If you didn't realize im not really what you would call a programmer. i just do it for the fun of it but have done it for quite a while though. Too bad i never actually get good at anything. nonetheles big thank you for helping me out!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.