22 lines
630 B
GDScript
22 lines
630 B
GDScript
extends CharacterBody2D
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|
var speed = 750
|
|
var life_time = 1.0
|
|
|
|
func start(_position, _direction):
|
|
rotation = _direction
|
|
position = _position
|
|
velocity = Vector2(speed, 0).rotated(rotation)
|
|
|
|
func _physics_process(delta):
|
|
var collision = move_and_collide(velocity * delta)
|
|
if collision:
|
|
velocity = velocity.bounce(collision.get_normal())
|
|
if collision.get_collider().has_method("hit"):
|
|
collision.get_collider().hit()
|
|
life_time -= delta
|
|
if life_time <= 0:
|
|
queue_free()
|