Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | malkav182 |
I’m trying to make a smooth transition between two nodes where they should switch positions when the player character turns around. using Tween I was able to do it, but I got a problem. If the player makes this movement too much (like turn left > right > left) the nodes stuck behind the player. I believe the Tween is behaving like that because I’m using the position of each node as a destination for each of them. So, when the player turns to a side and then turn to the other side, the Tween will get the position when the nodes are in their halfway from the destination position.
if Input.is_action_pressed("ui_right"):
motion.x = SPEED * run_mod
right = true
turn(right , delta)
old_right = right
$sprite.frames.set_animation_speed("walk" , run_frames * run_mod)
$sprite.play("walk")
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED * run_mod
right = false
turn(right , delta)
old_right = right
$sprite.frames.set_animation_speed("walk" , run_frames * run_mod)
$sprite.play("walk")
else:
motion.x =0
$sprite.play("idle")
...
func turn(val , delta):
var tween_atk = get_node("tween_atk")
var tween_dfs = get_node("tween_dfs")
var atk_pos = $attack_sphere.position
print("atk "+ str(atk_pos))
var dfs_pos = $defense_sphere.position
print("dfs "+ str(dfs_pos))
var dur = 1
if val == true:
$sprite.flip_h = false
self.get_tree().set_group("spheres" , "flip_h" , false)
else:
$sprite.flip_h = true
self.get_tree().set_group("spheres" , "flip_h" , true)
if old_right == right:
return
else:
var old_atk = $attack_sphere.position
tween_atk.interpolate_property($attack_sphere , "position" , atk_pos , dfs_pos , dur , Tween.TRANS_LINEAR, Tween.EASE_IN_OUT , 0)
tween_atk.start()
tween_dfs.interpolate_property($defense_sphere , "position" , dfs_pos , old_atk , dur , Tween.TRANS_LINEAR , Tween.EASE_IN_OUT , 0)
tween_dfs.start()
$attack_sphere/sight.position.x = $attack_sphere/sight.position.x * -1
I want to make the node reaches the destination to the side it must go dependent to where the player turns. For example, if the player turns left, the nodes start the transition and if they are halfway and the player turns to the opposite, the script should transition again to switch sides again from where they currently are.