#What can I do to simplify this script?

1 messages · Page 1 of 1 (latest)

sacred cliff
#

At the start you could do if not canmove:
return

#

And remove all the canmoves from the if statements

rain cedar
sacred cliff
#

I think you need to do 4 if statements to set the facing but I could br wrong

sacred cliff
rain cedar
sacred cliff
#

func _physics_process(delta):
if not canmove:
return
if Input.is_action_pressed("up") :
$Flare.flip_h = false
canmove = false
var move = create_tween()
move.tween_property(self, "position:y", (position.y - 16), .2)
move.finished.connect(allow_movement)
$Flare/AnimationPlayer.play("walkU")
facing = "up"
if Input.is_action_pressed("down") :
$Flare.flip_h = false
canmove = false
var move = create_tween()
move.tween_property(self, "position:y", (position.y + 16), .2)
move.finished.connect(allow_movement)
$Flare/AnimationPlayer.play("walkD")
facing = "down"
if Input.is_action_pressed("left"):
$Flare.flip_h = true
canmove = false
var move = create_tween()
move.tween_property(self, "position:x", (position.x - 16), .2)
move.finished.connect(allow_movement)
$Flare/AnimationPlayer.play("walkH")
facing = "left"
if Input.is_action_pressed("right"):
$Flare.flip_h = false
canmove = false
var move = create_tween()
move.tween_property(self, "position:x", (position.x + 16), .2)
move.finished.connect(allow_movement)
$Flare/AnimationPlayer.play("walkH")
facing = "right"
if !Input.is_anything_pressed():
if facing == "up":
$Flare/AnimationPlayer.play("idleU")
if facing == "down":
$Flare/AnimationPlayer.play("idleD")
if facing == "left":
$Flare/AnimationPlayer.play("idleH")
if facing == "right":
$Flare/AnimationPlayer.play("idleH")

#

this is identical to what you have posted but simplified like you were asking

#

i mean there are a ton of stuff i'm sure you can add to simplify it but this is the most obvious one