Godot Version
Godot 4.4
Question
I am using raycast arrows detect if they are colliding with tiles in tile map. If colliding then a variable is_touching is set to true and the raycast is disabled so it doesn’t keep resetting the variable to true as I play the game and interact with other characters.
My problem is that I have code which temporarily sticks the character to the wall if touching, then this is switched back to false and can move freely again if other input happens in the world, however, at my current state, I am in a bind.
I figured I would use a timer so that if the character area has exited the wall, then a timer would start to re enable the raycast, here is the code I have so far:
func _on_area_2d_body_exited(body: Node2D) → void:
if body.is_in_group(“Wall”):
is_touching = false
timer.start()
func _on_timer_timeout() → void:
RayCastVar.enabled = true
However the timer starts as soon as I make a different character touch a wall. I set them separately so they have their own scenes and scripts so I am having a hard time thinking what the issue is. I would think they’d have no issues having their own timers.
I can’t think of why this is happening, when I remove the timer logic everything seems to act how it’s supposed to. Apologies for all the rambling. I appreciate you reading through
Want to note also that the timer is a node in my character’s scene
The problem is that body is not specific to the Player.
Do something like:
if body.is_in_group("Player") and body.is_in_group("Wall"):
You just need the body to be the Player
Thank you for your response. I am new to this so I am having a hard time understanding. I apologize for my confusion. Are you saying to put the tile set in a group for the player character as well as the group wall? Or are you saying to put the character in a group and see if the body is the player body from that group?
Not sure if this bit of info helps but, the area_exited function that I put in the post is in the character script, I have an area 2D detecting bodies entered on the same layer as the tile map
I just tried to include the player group to that function and it didn’t work
thank you for digging into it with me, I am lost
the character is specificatlly in that group but it didn’t work for me and then I tried adding the tile set and it didn’t change the result either.
I can’t figure out where I went wrong. Especially when everything looks like it’s running fine and it’s just this timer I can’t seem to tell the conditions I want it to meet before starting or moreso it seems to want to take in more conditions. Which makes me feel like I do have an error elsewhere, but I just can’t figure how since I am making such specific declarations in these places, which imo seem like they aren’t messing with anything else
if body.is_in_group("Wall") and body.is_in_group("Character"):
is_touching= false
timer.start()```
sorry my answer was wrong, I’m overnighted…
try Print and let me know what it says in the debugger:
func _on_area_2d_body_exited(body: Node2D) -> void:
print("Body exited: ", body.name)
if body.is_in_group("Wall"):
print("Wall exited, starting timer")
is_touching = false
timer.start()
No worries at all. I really appreciate you responding.
Putting in your code gave me this. What’s interesting, is this only worked on the floor, which I’m having no issues with. The timer is actually for a raycast to detect if the character is touching a wall, and that won’t even exit the wall. Once I touch the other character to the tilemap this timer starts and glues me to the wall
I got to be messing up somewhere but I just can’t figure out where. Thank you for checking in with me on this. Hope you get some rest
Wall exited, starting timer
I actually got another issue figured out which removes the need I have for these timers. Still wonder where I went wrong because it could come back to bite me later. But for now all sunshine and rainbows.
Thanks for your help with this
Maybe make a variable and name it Collider, then equal that variable to your raycast and add a .get_collider()?
For example:
Var collider = $Raycast.get_collider()
By the way here’s a tip! You can use triple ` on the start of your code and at the end of your code to make it have a dark box around it, to make it stand out!
Thank you for your solution and the formatting tip when wanting to highlight the code.
Appreciate it!
1 Like
No problem!
See this is how it’ll look:
func _on_area_2d_body_exited(body: Node2D) → void:
if body.is_in_group(“Wall”):
is_touching = false
timer.start()
func _on_timer_timeout() → void:
RayCastVar.enabled = true
I recommend you to Copy your code to make it have indents! (If you don’t know what indents are… they are those arrows that you’ll see on the left side, if you disabled those arrows through settings, then you wont see arrows)
I can’t see these arrows on the left side, I didn’t realize I had anything disabled. I tried just using the tab key and it didn’t do anything… I am very new lol, even though, I am the type of person to say that for years I am new here. I looked it up and it said to go into editor settings but also that spacing 4 times would work? Sorry to keep bugging you but do you know if this is true?
1 Like
Hi, i’m not sure if spacing 4 times would count it as an indent, i think it will give an error
So
you mean you dont see this arrow?

The one on the "animationplayer.play(“hurt”)
Thats what i meant by the “left side”
If you’re not seeing that then you might be looking at this symbol:

The one that says func on_dash_cooldown_timeout():
That should be visible to pc and mobile users
Oh my goodness. Thank you for clarifying. I definitely exposed my inexperience here as I thought you were referring to arrows on this forum for formatting to leave comment 
1 Like
Sorry to bother you again, if you are still on I have a question about like how I should post here. If I have a question, that is like technically related but is similar, should I just make a new post? I ended up ditching the raycasts, but I’m back into timerland. So I wasn’t sure if like I should respond to this post or make a new one. I’m seeing they all like pop up on new like every response? and I feel really silly having like 5 questions rapid fire. Especially if that’s not how it’s done
1 Like
Hi, i’m also decently new here, and i’m not really sure if i get you but, i think yes, i made a topic about “why am i at -1 hp” and i told them a new problem about something something, but that problem wasnt really the main thing or really similiar to what my topic was, it was just another problem, so it’s alright to ask something different in the same post
Thank you very much, will keep this in mind!
1 Like