Attention | Topic was automatically imported from the old Question2Answer platform. | |
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