June 2018
Beginner to intermediate
298 pages
7h 38m
English
Add the following script:
extends KinematicBody2Dexport (int) var speedexport (int) var gravityvar velocity = Vector2()var facing = 1func _physics_process(delta): $Sprite.flip_h = velocity.x > 0 velocity.y += gravity * delta velocity.x = facing * speed velocity = move_and_slide(velocity, Vector2(0, -1)) for idx in range(get_slide_count()): var collision = get_slide_collision(idx) if collision.collider.name == 'Player': collision.collider.hurt() if collision.normal.x != 0: facing = sign(collision.normal.x) velocity.y = -100 if position.y > 1000: queue_free()
In this script, the facing variable tracks the direction of movement (1 or -1). As with the player, when moving, you iterate through the slide collisions. If the colliding object ...
Read now
Unlock full access