So basically I’m trying to make a Meshinstance3D change color if I stand on it (which already works if I click my left mouse button).
So I made a variable “active” which I turn on if I enter an area3d and I turn it of if I exit it.
Seems very simple and logical to me, but if I stand in the area3d, the boolean just keeps switching on and off. I can’t find anything about it online, so all help would be much appreciated.
(Please, view the attached and screenshots)
I’m not quite sure what is causing the problem but it is probably worth checking if there aren’t any other bodies interfering with your area detection, like the floor for example. Can you change the code to the following so we can see who is triggering the signals?
func _on_area_3d_body_exited(body):
active = false
print("Exiting:" + body.name)
func _on_area_3d_body_entered(body):
active = true
print("Entering:" + body.name)
If there are bodies that aren’t the player popping up in the output, then you can prevent them from interfering by adding a check in those two functions. Note that you have to add class_name Player inside of your player script for this to work.
func _on_area_3d_body_exited(body):
if !body is Player:
return
active = false
func _on_area_3d_body_entered(body):
if !body is Player:
return
active = true
Alternatively you could also change the collision mask of your portal’s area to only detect the player in the first place; or if you later want to change it so other objects like NPCs or Rigidbodies can use the portal as well.
Hey there,
First off all thank you for trying to solve this problem with me.
I’ve changed the Collision layers and masks, but to no avail.
The function seems to work fine with print statements, but for some reason, the boolean only freaks out inside of the _on_area_3d_body_entered function (since it works perfectly fine outside of that)
Sadly enough, it’s probably a bug. I’ve tested the same code in another project of mine and there it works perfectly.
Thank you for your time and effort though.