0 votes

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 applyimpulse when only ("uiup" ) action is pressed.
what is the best solution .... create a function for this or boolean variable .... var impulseleft = bool (false)?
.....one side question...in the apply
impulse I have Vector3(140,0,0)....is 140 okay ,can it be so?

in Engine by (450 points)

....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.

1 Answer

+1 vote
Best answer

Answer is in the comment :-)

by (450 points)
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 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 webmaster@godotengine.org with your username.