How to daley function?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek
:warning: Old Version Published before Godot 3 was released.

Hi, I have problem with my script:

func _input(event):
	if event.is_action_released("ui_accept"): # when I am pressing a key
		get_node("RigidBody2D").set_rotd(get_rotd()-5) # RigidBody2D is rotating to check collision
		if !is_colliding(): # if collision is false
			get_node("Tween").interpolate_property(self, "transform/rot", 0, -90, 1, Tween.TRANS_QUAD, Tween.EASE_IN_OUT) # animation is...
			get_node("Tween").start() # ... starting

After making this action my object should stay still (without any rotation, because is_colliding() return true but after pressing a key object is rotating very slightly (it’s not perfect 0 degrees).

For a test I have made function like this:

func _input(event):
	if event.is_action_pressed("ui_accept"): # when I am pressing a key
		get_node("RigidBody2D").set_rotd(get_rotd()-5)  # RigidBody2D is rotating to check collision
		for x in range(0, 1): # and starts short loop
			if x == 0: # at 0...
				if is_colliding() == true:# ... it's checking for collision
					break # and eventually break
				else: # or continue
					continue
			if x == 1: at 1...
				get_node("Tween").interpolate_property(self, "transform/rot", get_rotd(), get_rotd()-90, 1, Tween.TRANS_QUAD, Tween.EASE_IN_OUT) # animation is...
				get_node("Tween").start() # ... starting

And this one is working ok but it’s looks like a mess. How should I deal with this problem correctly?

Best :slight_smile:

:bust_in_silhouette: Reply From: Omicron

Yes, apparently some unnecessary looping and tests :slight_smile:

func _input(event):
    if event.is_action_pressed("ui_accept"): # when I am pressing a key
        get_node("RigidBody2D").set_rotd(get_rotd()-5)  # RigidBody2D is rotating to check collision
        if not(is_colliding()):
            get_node("Tween").interpolate_property(self, "transform/rot", get_rotd(), get_rotd()-90, 1, Tween.TRANS_QUAD, Tween.EASE_IN_OUT) # animation is...
            get_node("Tween").start() # ... starting

Now I just realize it is identical to your first code. I don’t really see what your second code is supposed to do ^^

Omicron | 2017-06-14 16:31

Hehe :wink:
So, with your code after pressing key object is rotating for small amont (like 1 degree) and then stop. With this test version (with loop) it’s working correctly.

websterek | 2017-06-16 09:10

Here is why, then : enter image description here

The loop doesn’t loop… so actually

        get_node("Tween").interpolate_property(self, "transform/rot", get_rotd(), get_rotd()-90, 1, Tween.TRANS_QUAD, Tween.EASE_IN_OUT) # animation is...
        get_node("Tween").start() # ... starting

is never executed.

Omicron | 2017-06-16 09:28