Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rayze |
extends KinematicBody2D
var vel = Vector2()
var ACCELLERATION = 500
var SPEED = 80
var FRICTION = 500
var GRAVITY = 100
var JUMPFORCE = 200
enum{
IDLE,
MOVE,
ATTACK
}
var state = IDLE
func _physics_process(delta):
match state:
MOVE:
attack()
apply_garvity()
move(delta)
jump()
IDLE:
move(delta)
attack()
apply_gravity()
jump()
ATTACK:
move(delta)
apply_garvity()
jump()
vel = move_and_slide(vel)
func move(delta):
var input_vector = Vector2()
input_vector.x = Input.get_action_strength(“player_right”) - Input.get_action_strength(“player_left”)
input_vector.normalized()
if vel != input_vector:
state = MOVE
$AnimatedSprite.play("Walk")
vel = vel.move_toward(input_vector * SPEED, ACCELLERATION * delta)
else:
state = IDLE
$AnimatedSprite.play("Idle")
vel = vel.move_toward(Vector2.ZERO, FRICTION * delta)
if vel.x > 0:
$AnimatedSprite.flip_h = true
else:
$AnimatedSprite.flip_h = false
func jump():
$AnimatedSprite.play(“Jump”)
if Input.is_action_pressed(“player_up”):
vel.y = -JUMPFORCE
func attack():
state = ATTACK
func apply_gravity():
vel.y += GRAVITY
Hi! Sorry, what is the question? And could you use the code block to paste code? (it is the button with curly braces in the editor).
p7f | 2020-10-25 18:39