0 votes

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 :)

in Engine by (227 points)

1 Answer

0 votes

Yes, apparently some unnecessary looping and tests :-)

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
by (340 points)

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

Hehe ;)
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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.