Attention | Topic was automatically imported from the old Question2Answer platform. | |
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