Multiple Raycasts in One Sprite checking for multiple things help

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noob_Maker
:warning: Old Version Published before Godot 3 was released.

Okay, I’m planning to have a multi-raycast system where the bottom one that faces the bottom checks the ground for the spirte to be able to jump, and two at the sides cheking for walls so that the sprite have the ability to push off walls to wall jump and climb. I figured out how to have the jump one by doing this:

func is_on_ground():
if raycast.is_colliding():
	return true
else:
	return false

func _ready():
	CollisionShape = RectangleShape2D.new()
	raycast = get_node("RayCast2D")
	raycast.add_exception(self)
	set_fixed_process(true)
	set_gravity_scale(3)

But I have no idea how to get multiple raycasts checking for different things. Also the var for the push off for the walls will be half of the jumpforce(220) so I want the two additional raycasts keeping in mind of that. A little help here?

Oh and I’m going 2D. Just pointing that out before somebody gives me examples for code for 3D on accident.

:bust_in_silhouette: Reply From: MrMonk
if raycast_1.is_colliding():
   if raycast_1.get_collider().get_name() == "object":
      do_something
   elif raycast_1.get_collider().get_name() == "other_object":
     do_something_else

to use multiple raycasts, name them differently:

raycast_1 = get_node("left_ray")
raycast_2 = get_node("right_ray")

and so on.

Or, depending the use, you can cast an instant ray (or shape), check http://docs.godotengine.org/en/stable/classes/class_physics2ddirectspacestate.html#class-physics2ddirectspacestate-intersect-ray

eons | 2017-05-12 13:20

Thanks but the engine says that it can’t identify raycast_1 or raycast_2. Is it okay if they all called raycast but checks for all of the three raycasts since each one does different things?

Edit: Okay apparently that makes it that all of my raycasts not to work.

Noob_Maker | 2017-05-13 12:11

just for clarification for future readers (sorry for the necro) when you add the raycast2d node in the scene window, you can rename the raycast. so when you are typing the get node function you are actually referring to it by name

   raycast_down = get_node ("down")
   raycast_left = get_node ("left")
   raycast_right = get_node ("right")

so in this example I named my raycast2d nodes down, left, and right when I added them to the scene window. also in my example I named the variables raycast_down raycast_left raycast_right instead of you can name them anything that makes sense to you as long as you refer to them by the same name everytime. MrMonk was right in his answer but i thought I’d throw in a mini clarification for anyone who reads this afterwards.

5thofMay | 2017-06-25 16:52