I have a simple code from the standard game for Godot 3:
extends KinematicBody
export var speed = 14
export var fall_acceleration = 75
export var jump_impulse = 20
var velocity = Vector3.ZERO
func _physics_process(delta):
var direction = Vector3.ZERO
if Input.is_action_pressed("move_right"):
rotate_y(-25)
if Input.is_action_pressed("move_left"):
rotate_y(25)
if Input.is_action_pressed("move_back"):
direction.z += 1
if Input.is_action_pressed("move_forward"):
direction.z -= 1
if is_on_floor() and Input.is_action_just_pressed("jump"):
velocity.y += jump_impulse
velocity.x = direction.x * speed
velocity.z = direction.z * speed
velocity.y -= fall_acceleration * delta
velocity = move_and_slide(velocity, Vector3(0,180,0))
How can I change it so that the character walks forward and backward depending on his direction?