Hello, I have a problem where the player's position will reset whenever I press space. Originally the input was tied to a dash, but I removed all of the code, yet it is still causing problems. Is there a special setting I need to uncheck.
Here is the player code: (sorry if its not formatted correctly):
extends KinematicBody2D
#player vars
export var speed = 60;
export var max_speed = 230.50
export var accel = 45
export var friction = 8
export var velocity = Vector2.ZERO
var ammo = 100;
var bullet_scene = load("res://Scenes/Player/bullet.tscn")
export var health = 100
var canShoot = false
var weapon_index = 0
var melee_index = 0; ##increments
export var damage = 20
export var gunKnockback = 0.9
##var canDoExtraAttack = false
#getting animations
enum {
MOVE,
ATTACK
}
enum{
MELEE,
GUN
}
var CurrentWeapon = MELEE
var State = MOVE
onready var PlayerAnimations = $PlayerAnimations
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
onready var attackBox = $Pivot/Attack
onready var dashTimer = $DashTimer
func _ready():
GlobalWorld.Player = self
func moveState(_delta):
var input = Vector2.ZERO #empty vector
var mouse_left = Input.is_action_just_pressed("ui_mouse_left")
var mouse_right = Input.is_action_just_pressed("ui_mouse_right")
##var dash = Input.is_action_just_pressed("dash");
input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") #0 1 or -1
input.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input = input.normalized()
if input != Vector2.ZERO:
##attackBox.knockback_vector = input
animationTree.set("parameters/Idle/blend_position",input) ##set each blend space
animationTree.set("parameters/Run/blend_position",input)
animationTree.set("parameters/Attack/blend_position",input)
animationState.travel("Run") ##travel means it shifts to the next animation in tree
velocity += input * accel * _delta #moving the character
velocity = velocity.clamped(max_speed*_delta) ##making it feel smooth
else:
velocity = velocity.move_toward(Vector2.ZERO,friction*_delta)
animationState.travel("Idle")
move_and_slide(velocity*speed)
####Code for punches##############
if mouse_left and canShoot==false:
State = ATTACK #we can now attack
melee_index+=1; #each time we press attack this inc++
if melee_index > 2:
melee_index = 0
print("did attack")
print(melee_index)
if mouse_left and canShoot == true:
fire()
if mouse_right:
weapon_index+=1
canShoot=true
CurrentWeapon = GUN
if weapon_index > 1:
weapon_index = 0
canShoot = false
CurrentWeapon = MELEE
if health < 0:
self.queue_free()
func _physics_process(_delta):
match State:
MOVE:
moveState(_delta)
ATTACK:
meleeState(_delta)
match CurrentWeapon:
MELEE:
print("cant Shoot")
GUN:
print("gun")
func meleeState(_delta):
animationState.travel("Attack")
func onAnimEnd():
State = MOVE
print("stopping animation")
func fire():
var BULLET = bullet_scene.instance()
BULLET.position = get_global_position()
get_parent().add_child(BULLET)
ammo -= 1
func _on_HitBox_body_entered(body):
pass