![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Unknowledge |
I started using godot 3 days ago and I’ve write the following code for the player:
extends KinematicBody2D
const SPEED = 200
var movedir = Vector2(0,0)
func _physics_process(delta):
controls_loop()
movement_loop()
if Input.is_action_pressed("ui_left"):
$AnimationPlayer.play("Walk Left")
elif Input.is_action_pressed("ui_right"):
$AnimationPlayer.play("Walk Right")
elif Input.is_action_pressed("ui_up"):
$AnimationPlayer.play("Walk Up")
elif Input.is_action_pressed("ui_down"):
$AnimationPlayer.play("Walk Down")
else:
$AnimationPlayer.play("Idle")
func controls_loop():
var LEFT = Input.is_action_pressed("ui_left")
var RIGHT = Input.is_action_pressed("ui_right")
var UP = Input.is_action_pressed("ui_up")
var DOWN = Input.is_action_pressed("ui_down")
movedir.x = -int(LEFT) + int(RIGHT)
movedir.y = -int(UP) + int(DOWN)
func movement_loop():
var motion = movedir.normalized() * SPEED
move_and_slide(motion, Vector2(0,0))
What I want to do is that when I press SHIFT, the player speed doubles or multiplies it by 1.5. Anyone know how to do this?