I'm trying to make my 2d character move and jump when a or d pressed the same time as space pressed. I think I have tried anything but I can't find the solution. What I did wrong?
EDIT:
extends KinematicBody2D
onready var sprite = $Sprite
onready var collision = $Collision
onready var mapManager = getparent().getnode("RoomManager")
var acceleration
var friction
var baseSpeed
var speed
var jumpPower
var gravity
var state
var level
var room
var moveVec
var velocity
var climbing
var health
var rng = RandomNumberGenerator.new()
var gameSeed = 0
var lastStep = 0
export (bool) var canFall = true
export (bool) var canCollide = true
var onFloor = true
enum {IDLE, WALK, RUN, JUMP, FALL, CROUCH, LADDERCLIMB, SLIDESTART, SLIDELOOP, SLIDEEND,
WALLSLIDE, ATTACK, COMBO, CRITICAL, SPELL, SHIELD, DAMAGE, DEATH, WALKJUMPLEFT, WALKJUMP_RIGHT}
func _ready():
start()
func start():
if canCollide:
collision.disabled = false
else:
collision.disabled = true
moveVec = Vector2(1,0)
velocity = Vector2.ZERO
climbing = false
health = 100
state = IDLE
level = 1
room = 1
if gameSeed == 0:
rng.randomize()
else:
rng.set_seed(gameSeed)
acceleration = 500
friction = 700
baseSpeed = 100
speed = baseSpeed
jumpPower = 600
gravity = 50
func physicsprocess(delta):
stateMachine(delta)
func stateMachine(delta):
particles()
inputs()
position.x = clamp(position.x , -1, 337)
match state:
IDLE:
idlestate(delta)
WALK:
walkstate(delta)
RUN:
runstate(delta)
JUMP:
jumpstate()
FALL:
fallstate()
CROUCH:
crouchstate()
LADDERCLIMB:
ladderclimbstate()
SLIDESTART:
slidestartstate()
SLIDELOOP:
slideloopstate()
SLIDEEND:
slideendstate()
WALLSLIDE:
wallslidestate()
ATTACK:
attackstate()
COMBO:
combostate()
CRITICAL:
criticalstate()
SPELL:
spellstate()
SHIELD:
shieldstate()
DAMAGE:
damagestate()
DEATH:
deathstate()
velocity = moveandslide(velocity, Vector2.UP)
if isonfloor():
onFloor = true
else:
onFloor = false
if not isonfloor() and canFall:
velocity.y += gravity
func particles():
if velocity.x == 0:
lastStep = -1
if sprite.animation == "Run":
if sprite.frame == 0 or sprite.frame == 3:
if lastStep != sprite.frame:
lastStep = sprite.frame
var footstep = Preloads.dustParticle.instance()
footstep.emitting = true
footstep.globalposition = Vector2(globalposition.x, globalposition.y)
getparent().add_child(footstep)
func inputs():
if Input.isactionpressed("left") and not Input.isactionpressed("run"):
state = WALK
sprite.fliph = true
moveVec.x = -1
elif Input.isactionpressed("right") and not Input.isactionpressed("run"):
state = WALK
sprite.fliph = false
moveVec.x = 1
elif Input.isactionpressed("left") and Input.isactionpressed("run"):
state = RUN
sprite.fliph = true
moveVec.x = -1
elif Input.isactionpressed("right") and Input.isactionpressed("run"):
state = RUN
sprite.fliph = false
moveVec.x = 1
elif Input.isactionpressed("crouch") and Input.isactionpressed("rightclick"):
state = SHIELD
elif Input.isactionpressed("crouch"):
state = CROUCH
elif Input.isactionpressed("slide"):
state = SLIDESTART
elif Input.isactionpressed("up") and climbing:
state = LADDERCLIMB
else:
state = IDLE
if Input.is_action_just_pressed("jump"):
state = JUMP
func idlestate(delta):
sprite.play("Idle")
velocity = velocity.movetoward(Vector2.ZERO, friction * delta)
func walkstate(delta):
sprite.play("Walk")
speed = baseSpeed
velocity = velocity.movetoward(moveVec * speed, acceleration * delta)
func runstate(delta):
sprite.play("Run")
speed = baseSpeed * 2
velocity = velocity.movetoward(moveVec * speed, acceleration * delta)
func jump_state():
if onFloor:
sprite.play("BeforeJump")
sprite.play("Fly")
velocity.y -= jumpPower
sprite.play("ReloadJump")
state = FALL
func fallstate():
sprite.play("Fall")
velocity.y += gravity
if ison_floor():
sprite.play("Land")
func crouch_state():
sprite.play("Crouch")
velocity = Vector2.ZERO
func ladderclimbstate():
pass
func slidestartstate():
pass
func slideloopstate():
pass
func slideendstate():
pass
func wallslidestate():
pass
func attack_state():
pass
func combo_state():
pass
func critical_state():
pass
func spell_state():
pass
func shield_state():
sprite.play("Shield")
func damage_state():
pass
func death_state():
pass