How to make RayCast2D look in the same direction as the Player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By literallynick_

So, I watched some tutorials and managed to get my movement done:

extends KinematicBody2D

var moveSpeed : int = 250

var vel : Vector2 = Vector2()
var facingDir : Vector2 = Vector2()

onready var rayCast = get_node("RayCast2D")

func _physics_process(delta):
	
	vel = Vector2()
	
	# inputs
	if Input.is_action_pressed("move_up"):
		vel.y -= 1
		facingDir = Vector2(0, -1)
	if Input.is_action_pressed("move_down"):
		vel.y += 1
		facingDir = Vector2(0, 1)
	if Input.is_action_pressed("move_left"):
		vel.x -= 1
		facingDir = Vector2(-1, 0)
	if Input.is_action_pressed("move_right"):
		vel.x += 1
		facingDir = Vector2(1, 0)
	
	move_and_slide(vel * moveSpeed)
	

And now I want to make Players RayCast look in the same direction as the player, which
I can’t understand how to do, I want to do it so I can interact with stuff using the RayCast, would really appreciate help with this one!

Add a node 2d to the player, and under the node 2d add the raycast. Than in the code you can set the node 2ds scale to -1 whenever you want to flip the raycast.

Millard | 2020-11-04 16:15

:bust_in_silhouette: Reply From: Surtarso

you can use the same logic of your “facingDir” variable to the raycast “cast_to” vector2, or just hard-set it to one direction and flip it ( *-1) when you flip direction

so for example

Vector2.cast_to(0, -1)

?

literallynick_ | 2020-11-05 19:01

raycast.cast_to = vector2(x,y)

you can also split if only need one direction with

raycast.cast_to.x = int

Surtarso | 2020-11-05 19:11

oh i see :0
thank you so much for response!
this is easier that i thought it would be

literallynick_ | 2020-11-05 19:16