Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dimax_93 |
Hello,
I am starting now with Godot, and I don’t understand why if I push the key to move, the character moves just once and then stops (even if key is still pushed)
`extends KinematicBody
var velocity = Vector3 (0,0,0)
const WALK = 5
const RUN = 30
const GRAV = 9.8
const JUMP = 5
Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func handle_input ():
if Input.is_action_just_pressed(“ui_right”) and Input.is_action_just_pressed(“ui_left”):
velocity.x = 0
elif Input.is_action_just_pressed(“ui_right”):
if Input.is_action_just_pressed(“ui_shift”):
velocity.x = RUN
else:
velocity.x = WALK
elif Input.is_action_just_pressed(“ui_left”):
if Input.is_action_just_pressed(“ui_shift”):
velocity.x = -RUN
else:
velocity.x = -WALK
else:
velocity.x = 0
if Input.is_action_just_pressed(“ui_up”) and Input.is_action_just_pressed(“ui_down”):
velocity.z = 0
elif Input.is_action_just_pressed(“ui_up”):
if Input.is_action_just_pressed(“ui_shift”):
velocity.z = -RUN
else:
velocity.z = -WALK
elif Input.is_action_just_pressed(“ui_down”):
if Input.is_action_just_pressed(“ui_shift”):
velocity.z = RUN
else:
velocity.z = WALK
else:
velocity.z = 0
if Input.is_action_just_pressed(“ui_select”) and is_on_floor():
velocity.y = JUMP
func _physics_process(delta):
handle_input()
if not is_on_floor():
velocity.y -= GRAV * delta
move_and_slide(velocity , Vector3.UP)`
Please help!
Thanks a lot in advance