feat: Use wait parameter instead of immediate for turn_to and set_angle (#403)
Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -443,10 +443,8 @@ func _angle_is_between(
|
|||||||
# #### Parameters
|
# #### Parameters
|
||||||
#
|
#
|
||||||
# - deg int angle to set the character
|
# - deg int angle to set the character
|
||||||
# - immediate
|
# - wait float Wait this amount of seconds until continuing with turning around
|
||||||
# If true, direction is switched immediately. Else, successive
|
func set_angle(deg: int, wait: float = 0.0) -> void:
|
||||||
# animations are used so that the character turns to target angle.
|
|
||||||
func set_angle(deg: int, immediate = true) -> void:
|
|
||||||
if deg < 0 or deg > 360:
|
if deg < 0 or deg > 360:
|
||||||
escoria.logger.report_errors(
|
escoria.logger.report_errors(
|
||||||
"movable.gd:set_angle()",
|
"movable.gd:set_angle()",
|
||||||
@@ -454,37 +452,35 @@ func set_angle(deg: int, immediate = true) -> void:
|
|||||||
)
|
)
|
||||||
moved = true
|
moved = true
|
||||||
|
|
||||||
if immediate:
|
var current_dir = last_dir
|
||||||
last_dir = _get_dir_deg(deg, parent.animations)
|
var target_dir = _get_dir_deg(deg, parent.animations)
|
||||||
|
|
||||||
# The character may have a state animation from before, which would be
|
var way_to_turn = get_shortest_way_to_dir(current_dir, target_dir)
|
||||||
# resumed, so we immediately force the correct idle animation
|
|
||||||
if parent.get_animation_player().get_animation() != \
|
|
||||||
parent.animations.idles[last_dir].animation:
|
|
||||||
parent.get_animation_player().play(
|
|
||||||
parent.animations.idles[last_dir].animation
|
|
||||||
)
|
|
||||||
pose_scale = -1 if parent.animations.idles[last_dir].mirrored else 1
|
|
||||||
else:
|
|
||||||
var current_dir = last_dir
|
|
||||||
var target_dir = _get_dir_deg(deg, parent.animations)
|
|
||||||
|
|
||||||
var way_to_turn = get_shortest_way_to_dir(current_dir, target_dir)
|
var dir = current_dir
|
||||||
|
while dir != target_dir:
|
||||||
|
dir += way_to_turn
|
||||||
|
if dir >= parent.animations.dir_angles.size():
|
||||||
|
dir = 0
|
||||||
|
if dir < 0:
|
||||||
|
dir = parent.animations.dir_angles.size() - 1
|
||||||
|
|
||||||
var dir = current_dir
|
parent.get_animation_player().play(
|
||||||
while dir != target_dir:
|
parent.animations.idles[dir].animation
|
||||||
dir += way_to_turn
|
)
|
||||||
if dir >= parent.animations.dir_angles.size():
|
if wait > 0.0:
|
||||||
dir = 0
|
yield(get_tree().create_timer(wait), "timeout")
|
||||||
if dir < 0:
|
pose_scale = -1 if parent.animations.idles[dir].mirrored else 1
|
||||||
dir = parent.animations.dir_angles.size() - 1
|
|
||||||
|
|
||||||
parent.get_animation_player().play(
|
last_dir = _get_dir_deg(deg, parent.animations)
|
||||||
parent.animations.idles[dir].animation
|
|
||||||
)
|
|
||||||
yield(parent.get_animation_player(), "animation_finished")
|
|
||||||
pose_scale = -1 if parent.animations.idles[dir].mirrored else 1
|
|
||||||
|
|
||||||
|
# The character may have a state animation from before, which would be
|
||||||
|
# resumed, so we immediately force the correct idle animation
|
||||||
|
if parent.get_animation_player().get_animation() != \
|
||||||
|
parent.animations.idles[last_dir].animation:
|
||||||
|
parent.get_animation_player().play(
|
||||||
|
parent.animations.idles[last_dir].animation
|
||||||
|
)
|
||||||
update_terrain()
|
update_terrain()
|
||||||
|
|
||||||
|
|
||||||
@@ -493,17 +489,15 @@ func set_angle(deg: int, immediate = true) -> void:
|
|||||||
# #### Parameters
|
# #### Parameters
|
||||||
#
|
#
|
||||||
# - item_id id of the object to face.
|
# - item_id id of the object to face.
|
||||||
# - immediate
|
# - float Wait this amount of seconds until continuing with turning around
|
||||||
# If true, direction is switched immediately. Else, successive
|
func turn_to(item: Node, wait: float = 0.0) -> void:
|
||||||
# animations are used so that the character turns to target angle.
|
|
||||||
func turn_to(item: Node, immediate = true) -> void:
|
|
||||||
set_angle(
|
set_angle(
|
||||||
wrapi(
|
wrapi(
|
||||||
rad2deg(parent.get_position().angle_to_point(item.get_position())),
|
rad2deg(parent.get_position().angle_to_point(item.get_position())),
|
||||||
0,
|
0,
|
||||||
360
|
360
|
||||||
),
|
),
|
||||||
immediate
|
wait
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# `set_angle object degrees [immediate]`
|
# `set_angle object degrees [wait]`
|
||||||
#
|
#
|
||||||
# Turns object to a degrees angle without animations. 0 sets object facing
|
# Turns object to a degrees angle without animations. 0 sets object facing
|
||||||
# forward, 90 sets it 90 degrees clockwise ("east") etc. When turning to the
|
# forward, 90 sets it 90 degrees clockwise ("east") etc. When turning to the
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
# object must be player or interactive. degrees must be between [0, 360] or an
|
# object must be player or interactive. degrees must be between [0, 360] or an
|
||||||
# error is reported.
|
# error is reported.
|
||||||
#
|
#
|
||||||
|
# The wait parameter sets how long to wait for each intermediate angle. It
|
||||||
|
# defaults to 0, meaning the turnaround is immediate.
|
||||||
|
#
|
||||||
# @ESC
|
# @ESC
|
||||||
extends ESCBaseCommand
|
extends ESCBaseCommand
|
||||||
class_name SetAngleCommand
|
class_name SetAngleCommand
|
||||||
@@ -16,8 +19,8 @@ class_name SetAngleCommand
|
|||||||
func configure() -> ESCCommandArgumentDescriptor:
|
func configure() -> ESCCommandArgumentDescriptor:
|
||||||
return ESCCommandArgumentDescriptor.new(
|
return ESCCommandArgumentDescriptor.new(
|
||||||
2,
|
2,
|
||||||
[TYPE_STRING, TYPE_INT, TYPE_BOOL],
|
[TYPE_STRING, TYPE_INT, TYPE_REAL],
|
||||||
[null, null, true]
|
[null, null, 0.0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -36,12 +39,13 @@ func validate(arguments: Array):
|
|||||||
|
|
||||||
# Run the command
|
# Run the command
|
||||||
func run(command_params: Array) -> int:
|
func run(command_params: Array) -> int:
|
||||||
var immediate = command_params[2]
|
|
||||||
|
|
||||||
# HACK Countering the fact that angle_to_point() function gives
|
# HACK Countering the fact that angle_to_point() function gives
|
||||||
# angle against X axis not Y, we need to check direction using (angle-90°).
|
# angle against X axis not Y, we need to check direction using (angle-90°).
|
||||||
# Since the ESC command already gives the right angle, we add 90.
|
# Since the ESC command already gives the right angle, we add 90.
|
||||||
escoria.object_manager.get_object(command_params[0]).node\
|
escoria.object_manager.get_object(command_params[0]).node\
|
||||||
.set_angle(wrapi(int(command_params[1]) + 90, 0, 360), immediate)
|
.set_angle(
|
||||||
|
wrapi(int(command_params[1]) + 90, 0, 360),
|
||||||
|
command_params[2]
|
||||||
|
)
|
||||||
return ESCExecution.RC_OK
|
return ESCExecution.RC_OK
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# `turn_to object object_to_face [immediate]`
|
# `turn_to object object_to_face [wait]`
|
||||||
#
|
#
|
||||||
# Turns object to face another object.
|
# Turns object to face another object.
|
||||||
#
|
#
|
||||||
# Set immediate to true to show directly switch to the direction and not
|
# The wait parameter sets how long to wait for each intermediate angle. It
|
||||||
# show intermediate angles
|
# defaults to 0, meaning the turnaround is immediate.
|
||||||
#
|
#
|
||||||
# @ESC
|
# @ESC
|
||||||
extends ESCBaseCommand
|
extends ESCBaseCommand
|
||||||
@@ -14,8 +14,8 @@ class_name TurnToCommand
|
|||||||
func configure() -> ESCCommandArgumentDescriptor:
|
func configure() -> ESCCommandArgumentDescriptor:
|
||||||
return ESCCommandArgumentDescriptor.new(
|
return ESCCommandArgumentDescriptor.new(
|
||||||
2,
|
2,
|
||||||
[TYPE_STRING, TYPE_STRING, TYPE_BOOL],
|
[TYPE_STRING, TYPE_STRING, TYPE_REAL],
|
||||||
[null, null, false]
|
[null, null, 0.0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -421,10 +421,9 @@ func get_sprite() -> Node:
|
|||||||
# #### Parameters
|
# #### Parameters
|
||||||
#
|
#
|
||||||
# - deg: The angle degree to set
|
# - deg: The angle degree to set
|
||||||
# - immediate: Set the angle immediately. If false will show intermediate
|
# - wait: Wait this amount of seconds until continuing with turning around
|
||||||
# angles
|
func set_angle(deg: int, wait: float = 0.0):
|
||||||
func set_angle(deg: int, immediate = true):
|
_movable.set_angle(deg, wait)
|
||||||
_movable.set_angle(deg, immediate)
|
|
||||||
|
|
||||||
|
|
||||||
# Turn to face another object
|
# Turn to face another object
|
||||||
@@ -432,10 +431,9 @@ func set_angle(deg: int, immediate = true):
|
|||||||
# #### Parameters
|
# #### Parameters
|
||||||
#
|
#
|
||||||
# - deg: The angle degree to set
|
# - deg: The angle degree to set
|
||||||
# - immediate: Set the angle immediately. If false will show intermediate
|
# - float Wait this amount of seconds until continuing with turning around
|
||||||
# angles
|
func turn_to(object: Node, wait: float = 0.0):
|
||||||
func turn_to(object: Node, immediate = true):
|
_movable.turn_to(object, wait)
|
||||||
_movable.turn_to(object, immediate)
|
|
||||||
|
|
||||||
|
|
||||||
# Play the talking animation
|
# Play the talking animation
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ set_sound_state _music res://game/sfx/contemplation.ogg true
|
|||||||
wait 2
|
wait 2
|
||||||
walk_block player r1_destination_point2
|
walk_block player r1_destination_point2
|
||||||
wait 2
|
wait 2
|
||||||
set_angle player 225 false
|
set_angle player 225 0.2
|
||||||
wait 2
|
wait 2
|
||||||
walk_block player r1_destination_point3
|
walk_block player r1_destination_point3
|
||||||
wait 1
|
wait 1
|
||||||
turn_to player r1_r_exit false
|
turn_to player r1_r_exit
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
say player "Huh?"
|
say player "Huh?"
|
||||||
|
|
||||||
turn_to player 180 true
|
turn_to player slide_pos_1
|
||||||
|
|
||||||
say player "Nothing."
|
say player "Nothing."
|
||||||
|
|
||||||
turn_to player 0
|
turn_to player slide_pos_2 0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user