[英]Rotating an Area2D by 90 degrees after clicking (Godot)
问答的戈多论坛不想让我问我的问题,所以我们开始吧^^。
嘿,所以我希望当我按下右箭头按钮时,我的播放器 (Area2D) 会旋转 90 度。 但是,这不应该直接发生,而是需要一定的时间。 它应该保持在 0 90 180 270 360 450 ... 度。 通过按下左按钮,它应该移动 -90 度。 我目前有代码:
func _process(delta):
print($Player.rotation)
if rotate_to > $Player.get_rotation_degrees():
$Player.rotate((1 * delta)) ####### $Player.rotate((1 * delta) * speed)
abc = true
elif abc == true:
abc = false
$Player.set_rotation_degrees(int($Player.get_rotation_degrees()))
elif $Player.get_rotation_degrees() >= 360.0:
$Player.set_rotation_degrees(0)
rotate_to = 0
print($Player.get_rotation_degrees())
func _input(event):
if Input.is_key_pressed(KEY_RIGHT) and not event.is_echo():
rotate_to += 90
这就是它如何完美地旋转 90 度。 但是一旦我想提高速度以使其转得更快,因为它非常慢,并且矩形会破裂。 它不再是直线。
有人可以帮我解决这个问题吗?
如果要在两个值之间平滑过渡,最好使用 Tween 节点。 当您将 Tween 节点作为子节点添加到您想要旋转的播放器节点时,您可以在播放器节点中使用此代码。
#get child node with name Tween
onready var tween = get_node("Tween")
func _process(delta):
#test if action is presed and tween node is not running
if Input.is_action_just_pressed("ui_right") and not tween.is_active():
tween.interpolate_property(self,"rotation_degrees",rotation_degrees, rotation_degrees + 90,1,Tween.TRANS_LINEAR,Tween.EASE_IN)
tween.start()
if Input.is_action_just_pressed("ui_left") and not tween.is_active():
tween.interpolate_property(self,"rotation_degrees",rotation_degrees, rotation_degrees - 90,1,Tween.TRANS_LINEAR,Tween.EASE_IN)
tween.start()
您可以在 Godot 文档https://docs.godotengine.org/en/3.2/classes/class_tween.html 中找到更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.