Closed kazusaki1 closed 7 years ago
If the tower uses some predictive aiming, the problem might be that the code is using the NavMesh speed parameter to obtain the target's velocity. Speed is constant and non-zero even when the object is still. Use NavMesh's velocity, which returns a Vector3, to know target's velocity.
Vector3 targetVelocity = foundTarget.GetComponent<NavMeshAgent> ().velocity;
Most of the times the range is short enough and the projectile fast enough to ensure that the target gets hit. Since computing the intersection between projectile and target is quite costy, I have decide to abandon such feature. As mentioned on the previous comment, the main problem with the current implementation is that tower's fail at predicting the target's future position when it is static. I am going to fix that on this issue, and hence I will be changing the label ENHANCEMENT by the BUG one.
Target's velocity vs speed:
Note how (-3.8)^2 + (1.2)^2 is aproximately 16, speed squared.
I want to avoid having to work with the magnitude of the velocity vector, as computing squared roots is not free of cost. What I am going to do is keep speed but add a velocity check before assigning the target's speed:
var targetSpeed;
if target velocity components x and z are near zero:
targetSpeed = 0;
else
targetSpeed = target.speed;
I've faced some problems while fixing parabolic projectiles. Updated script uses parabolic trajectory equations to compute a vertical speed that allows the projectile to reach the target before falling into the ground:
/* Relevant parabolic movement equations (2D):
* y = y_0 + v_y * t - (g * t**2) / 2
* x = x_0 + v_x * t
*
* where:
* x - x_0 = distance to be traversed
* y - y_0 = height from ground to muzzle
* v_x = horizontal component of velocity
* v_y = vertical component of velocity
* g = gravity
*
* Simplifications: v_x = speed
*
* y = 0
* t = speed / x
* v_y = g * (d / v) / 2 - y_0 * (v / d)
* */
With this, the implementation satisfies the Definition of Done. Pull request is now open, I've digressed there about some issues concerning the parabolic projectiles.
Improve precision by fixing tower's predictive aiming. Investigate relation between projectile and tower reach.
Definition of Done:
DEPRECATED: Towers aim at where the projectile and the enemie's trajectory will intersect
Estimated time: 3 hour
Branch: dev_Issue242
Pull request: #287