22 lines
684 B
GDScript
22 lines
684 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
|
|
@onready var life_time: float = MapConfig.shotlife
|
|
|
|
func start(_position, _velocity, _direction):
|
|
rotation = _direction
|
|
position = _position
|
|
velocity = _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()
|