So, I m trying to make my rocket explode when it hits the wall. It only shows the first frame of the explosion animation when colliding.
This is the code:
extends KinematicBody2D
export(int) var speed=200
export(float) var rotation_speed=1.2
var velocity=Vector2()
var rotation_direction=0
var motion = Vector2()
var touchleft = false
var touchright = false
const is_colliding = false
const acceleration = 0.1
const UP = Vector2(0, -1)
const gravity = 0
const max_speed = 400
const max_fly_speed = 100
func _ready():
add_to_group("player")
func body_entered(body):
if body.is_in_group("enemy"):
get_tree().reload_current_scene()
func _physics_process(delta):
get_input()
motion.y += gravity
rotation+=rotation_direction*rotation_speed*delta
move_and_slide(velocity)
var collision = move_and_collide(velocity * delta)
if collision:
$Sprite.play("explode")
func get_input():
rotation_direction=0
velocity=Vector2()
motion.y = max(motion.y-acceleration, -max_fly_speed)
velocity=Vector2(0, -max_fly_speed).rotated(rotation)
$Sprite.play("gas")
if Input.is_action_pressed("ui_right") or touchright:
motion.x = min(motion.x+acceleration, max_speed)
rotation_direction+=1
elif Input.is_action_pressed("ui_left") or touchleft:
motion.x = max(motion.x-acceleration, -max_speed)
rotation_direction-=1
else:
motion.x = lerp(motion.x, 0, 0.2)
if Input.is_action_pressed("ui_down"):
get_tree().reload_current_scene()
motion = move_and_slide(motion, UP)
pass