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 isactionpressed to isactionjust_pressed but it has seems to have not work.
thanks again for any help on this issue!
extends KinematicBody
var MOVESPEED = 12
const JUMPFORCE = 30
const GRAVITY = 0.98
const MAXFALLSPEED = 30
const HLOOKSENS = 1.0
const VLOOKSENS = 1.0
onready var _cam = $Cambase
onready var anim = $Graphics/AnimationPlayer
var y_velo = 10
var velocity = 10
var onground = true
var hasdoublejumped = false
var justjumped = false
func ready():
anim.getanimation("walk").setloop(true)
Input.setmousemode(Input.MOUSEMODE_CAPTURED)
func input(event):
if event is InputEventMouseMotion:
_cam.rotationdegrees.x -= event.relative.y * VLOOKSENS
cam.rotationdegrees.x = clamp(cam.rotationdegrees.x, -90, 90)
rotationdegrees.y -= event.relative.x * HLOOK_SENS
func physicsprocess(delta):
var movevec = Vector3()
if Input.isactionpressed("moveforwards"):
movevec.z -= 1
if Input.isactionpressed("movebackwards"):
movevec.z += 1
if Input.isactionpressed("moveright"):
movevec.x += 1
if Input.isactionpressed("moveleft"):
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 playanim(name):
if anim.currentanimation == 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