Enemy
This commit is contained in:
@ -11,7 +11,7 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
if (Input.is_action_just_pressed("ui_accept") or Input.is_action_just_pressed("ui_up")) and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
|
18
scripts/slime.gd
Normal file
18
scripts/slime.gd
Normal file
@ -0,0 +1,18 @@
|
||||
extends Node2D
|
||||
|
||||
@onready var ray_cast_right: RayCast2D = $RayCastRight
|
||||
@onready var ray_cast_left: RayCast2D = $RayCastLeft
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
const speed = 60
|
||||
var direction = 1
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if ray_cast_right.is_colliding():
|
||||
direction = -1
|
||||
animated_sprite_2d.flip_h = true
|
||||
elif ray_cast_left.is_colliding():
|
||||
direction = 1
|
||||
animated_sprite_2d.flip_h = false
|
||||
|
||||
position.x += delta * speed * direction
|
Reference in New Issue
Block a user