Need some advice with disable a method in function in delta time

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bishop

Hi, so I need some solution/advice…I have a script where the player (rigidbody) rotates to the left and right while also moving a little in the x-axis to the left and right.

if Input.is_action_pressed("ui_left"): 
     rotate_y(-delta * PI/2)
     apply_impulse(Vector3(direction),Vector3(-140,0,0) * delta)
 if Input.is_action_pressed("ui_right"): 
      rotate_y(delta * PI/2) 
      apply_impulse(Vector3(direction),Vector(140,0,0) * delta)

…so I need to turn off apply_impulse when only (“ui_up” ) action is pressed.
what is the best solution … create a function for this or boolean variable … var impulse_left = bool (false)?
…one side question…in the apply_impulse I have Vector3(140,0,0)…is 140 okay ,can it be so?

…so I used three bool variables

var impulse_left = bool(false)
var impulse_right = bool(false)
var up_action = bool(false)

then in the

if Input.is_action_pressed("ui_left"):
                          rotate_y(-delta * PI/2)
                          if impulse_left == true:
                               apply_impulse(Vector 3(direction),Vector3(-140,0,0) * delta)

and in the _input(event): function

if event.is_action_pressed("ui_left):
      impulse_left = true
      if up_action == true:
            impulse_left = false

and of course

 if event.is_action_pressed("ui_up"):
        up_action = true
 if event.is_action_released("ui_up"):
        up_action = false

…and just it works.

Bishop | 2018-10-22 18:30

:bust_in_silhouette: Reply From: Bishop

Answer is in the comment :slight_smile: