how to stop sprite from flying in the air forever?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By starkid

I am currently having a problem with the main bit of my code. Instead of jumping and moving as it should, the character sprite just floats into the air out of nowhere when the game starts. I have tried to fix this by changing is_action_pressed to is_action_just_pressed but it has seems to have not work.
thanks again for any help on this issue!

	extends KinematicBody

var MOVE_SPEED = 12
const JUMP_FORCE = 30
const GRAVITY = 0.98
const MAX_FALL_SPEED = 30

const H_LOOK_SENS = 1.0
const V_LOOK_SENS = 1.0

onready var _cam = $Cambase
onready var anim = $Graphics/AnimationPlayer

var y_velo = 10

var velocity = 10
var on_ground = true
var has_double_jumped = false
var just_jumped = false

func _ready():
anim.get_animation(“walk”).set_loop(true)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):
if event is InputEventMouseMotion:
_cam.rotation_degrees.x -= event.relative.y * V_LOOK_SENS
_cam.rotation_degrees.x = clamp(_cam.rotation_degrees.x, -90, 90)
rotation_degrees.y -= event.relative.x * H_LOOK_SENS

func _physics_process(delta):
var move_vec = Vector3()
if Input.is_action_pressed(“move_forwards”):
move_vec.z -= 1
if Input.is_action_pressed(“move_backwards”):
move_vec.z += 1
if Input.is_action_pressed(“move_right”):
move_vec.x += 1
if Input.is_action_pressed(“move_left”):
move_vec.x -= 1

move_vec = move_vec.normalized()
move_vec = move_vec.rotated(Vector3(0, 1, 0), rotation.y)
move_vec *= MOVE_SPEED
move_vec.y = y_velo
move_and_slide(move_vec, Vector3(0, 1, 0))

func play_anim(name):
if anim.current_animation == name:
return
anim.play(name)

var grounded = is_on_floor()
var y_velo = GRAVITY
var just_jumped = false
if grounded and Input.is_action_just_pressed("jump"):
	just_jumped = true
	y_velo = JUMP_FORCE
if Input.is_action_just_pressed("jump"):
	if just_jumped == true and has_double_jumped == false:
		has_double_jumped = true
		y_velo = JUMP_FORCE

if grounded and y_velo <= 0:
	y_velo = -0.1
if y_velo < -MAX_FALL_SPEED:
	y_velo = -MAX_FALL_SPEED
:bust_in_silhouette: Reply From: cascas

I think you forgot to call playanim in your script.