Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | siten0308 |
Hello,
hopefully someone can assist, i have a GDScript, which it was C#, however C# is not doing so well, already found bugs on my first week of trying godot… anyways, what i am trying to accomplish is if character is moved right, then animation start or rotate etc., if left, same, but if stopped, play idle and stand in position.
Left works fine, however right doesn’t… what am i doing wrong??
GDscript is below:
extends KinematicBody2D
var sprite_node
export (int) var run_speed = 300
export (int) var jump_speed = -600
export (int) var gravity = 1200
var velocity = Vector2()
var jumping = false
func _ready():
set_process(true)
set_process_input(true)
sprite_node = get_node("Main_Character")
func get_input():
velocity.x = 0
var right = Input.is_action_pressed('ui_right')
var left = Input.is_action_pressed('ui_left')
var jump = Input.is_action_just_pressed('ui_select')
if jump and is_on_floor():
jumping = true
velocity.y = jump_speed
if right:
velocity.x += run_speed
sprite_node.set_flip_h(false)
$Main_Character.play("Run")
if left:
velocity.x -= run_speed
sprite_node.set_flip_h(true)
$Main_Character.play("Run")
else:
$Main_Character.play("Idle")
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
if jumping and is_on_floor():
jumping = false
velocity = move_and_slide
thanks in advance