Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parent é um kinematicbody2d
- collisionshape2d - capsule e radius 25 com height 0
- sprite - texture bola com scale 0.1, 0.1
- visibility notifier 2d - default no meio da bola e com sinal conectado no código
- //código
- extends KinematicBody2D
- var init_pos = Vector2.ZERO
- export var speed := 300
- export var speed_increment := 15
- var velocity
- var dir = Vector2.ZERO
- var collision
- func _ready() -> void:
- init_pos = get_global_position()
- print(init_pos)
- while dir.y == 0:
- dir.y = round(rand_range(-10, 10) / 10)
- while dir.x == 0:
- dir.x = round(rand_range(-10, 10) / 10)
- dir = dir.normalized()
- func _physics_process(delta: float) -> void:
- velocity = speed * dir
- collision = move_and_collide(velocity * delta)
- if collision:
- var collider = collision.collider
- if collider.name.find("wall") != -1:
- dir.y *= -1
- elif collider.name.find("player") != -1:
- dir.x *= -1
- if dir.y == 0:
- dir.y = round(rand_range(-10, 10) / 10)
- speed += speed_increment
- func _on_VisibilityNotifier2D_screen_exited() -> void:
- position = init_pos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement