如何解决Godot:2D Raycast的发展方向相反
刚开始学习Godot并遇到2D Raycasts左移而不是右或右移而不是左的问题。
所以我有一个基本的自上而下的2D游戏,播放器上有光线投射。向上和向下面向都可以很好地工作,只是左右造成了头痛。代码看起来不错,所以这就是为什么我在这里
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)
vel = vel.normalized()
move_and_slide(vel * moveSpeed)
manage_animations()
func manage_animations ():
if vel.x > 0:
play_animation("MoveRight")
elif vel.x < 0:
play_animation("MoveLeft")
elif vel.y < 0:
play_animation("MoveUp")
elif vel.y > 0:
play_animation("MoveDown")
elif facingDir.x == -1:
play_animation("IdleRight")
elif facingDir.x == 1:
play_animation("IdleLeft")
elif facingDir.y == -1:
play_animation("IdleUp")
elif facingDir.y == 1:
play_animation("IdleDown")
func _process(delta):
if Input.is_action_just_pressed("interract"):
try_interact()
func try_interact():
rayCast.cast_to = facingDir * interactDist
if rayCast.is_colliding():
if rayCast.get_collider() is KinematicBody2D:
rayCast.get_collider().take_damage(damage)
elif rayCast.get_collider().has_method("on_interact"):
rayCast.get_collider().on_interact(self)
我试图在左右移动中更改Vector2的x和y变量,并且在可行的同时,步行也变得一团糟。
有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。