I have followed a tutorial of Godot.
Top down Tank Battle Series:
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 :
-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.
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
var desired = (target.position - position).normalized() * speed
var steer = (desired - velocity).normalized() * steer_force
acceleration += seek()
velocity += acceleration * delta
velocity = velocity.clamped(speed)
rotation = velocity.angle()
lifetime = 0
position += velocity * delta
velocity = Vector2()
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.
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.