What are the modification necessary for the tutorial from 3.0 to 3.1?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Orkimede

Hello everyone.
I have followed a tutorial of Godot.
(Godot · KCC Blog
Top down Tank Battle Series:
Topdown Tank Battle: Part 1 · KCC Blog

http://kidscancode.org/blog/2018/04/godot3_tanks_part11/)

However, it seems that the version i have and the version described in said tutorial is not the same.
I think i’m working in 3.1 (is there any manipulation to check that?) while the tutorial is in 3.0.

My probleme are the followings, both in the 10th part of the tutorial :
(Topdown Tank Battle: Part 10 · KCC Blog)

-First, when i modified the code to include a tracking bullet, i got the following prolem:
Invalid get index "position" (on base: previously freed instance'). It happen when my tank is destroyed.

extends Area2D

export (int) var speed
export (int) var damage
export (float) var lifetime

var velocity = Vector2()

export (float) var steer_force = 0
var acceleration = Vector2()
var target = null

func start(_position, _direction, _target=null):
    position = _position
    rotation = _direction.angle()
    velocity = _direction * speed
    target = _target

func seek():
	var desired = (target.position - position).normalized() * speed
	var steer = (desired - velocity).normalized() * steer_force
	return steer

func _process(delta):
	if target!=null:
		acceleration += seek()
		velocity += acceleration * delta
		velocity = velocity.clamped(speed)
		rotation = velocity.angle()
	else:
		lifetime = 0
	position += velocity * delta

func explode():
	velocity = Vector2()
	$Sprite.hide()
	$Explosion.show()
	$Explosion.play("smoke")

func _on_Explosion_animation_finished():
	queue_free()

func _on_Bullet_body_entered(body):
    explode()
    if body.has_method('take_damage'):
        body.take_damage(damage)

func _on_Lifetime_timeout():
    explode()

So, from what i understood, in the function seek() (Line19), the part target.position try to access the position of the target. The problem is when the target is destroyed (freed).
Following the tutorial i added a condition to prevent this case. if target, (Line 25), that i modified to if tager != null. The problem persist as if the condition was not revelant.

What i though is that in the function start, we do a copy of the target (Line 17), that we then use. But in this case, the bullet should simply track the position of the tank at the moment it was fired.
So target = _target gives apparently a reference to my bullet.

In this case, why my condition if target != null does not prevent bugs?

-Second, I tried to realise the trail described in the tutorial. But i don’t manage to do the same way it was done in the tutorial. Even after i downloaded the project from the tutorial, it didn’t work the way intended. I tried to use a changing texture, but the texture change at the same moment for every particle. Is there a way to add a delay starting from the creation of the said particle?
I also tried to make a flow, but the problem is that it’s goes straight out of the missile, even when it turn, giving an artificial feeling.

Thank in advance.
Orkimede

Thank you, volzhs, for putting the code in red. Can you tell me how you do that?
Thank in advance.

Orkimede | 2019-04-08 14:01