@@ -269,9 +269,6 @@ public void updateHoming(Bullet b){
269
269
270
270
b .vel .set (Tmp .v31 );
271
271
data .zVel = Tmp .v31 .z ;
272
- Tmp .v1 .set (data .xAccel , data .yAccel ).setAngle (b .vel .angle ()); //TODO make the math take accel into account
273
- data .xAccel = Tmp .v1 .x ;
274
- data .yAccel = Tmp .v1 .y ;
275
272
}
276
273
}
277
274
}
@@ -431,10 +428,10 @@ public Bullet create3DVel(Entityc owner, Team team, float x, float y, float z, f
431
428
}
432
429
433
430
public Bullet create3DVel (Entityc owner , Team team , float x , float y , float z , float angle , float zVel , float gravity , float accel , float vel , float aimX , float aimY ){
434
- ArcBulletData data = new ArcBulletData (z , zVel , gravity ).setAccel (angle , accel );
431
+ ArcBulletData data = new ArcBulletData (z , zVel , gravity ).setAccel (accel );
435
432
436
433
Bullet bullet = beginBulletCreate (owner , team , x , y , aimX , aimY );
437
- bullet .initVel (angle , vel );
434
+ bullet .initVel (angle , vel ); //Non-zero so that rotation is correct
438
435
if (backMove ){
439
436
bullet .set (x - bullet .vel .x * Time .delta , y - bullet .vel .y * Time .delta );
440
437
data .backMove (bullet );
@@ -457,8 +454,7 @@ public Bullet create3DStraight(Entityc owner, Team team, float x, float y, float
457
454
Tmp .v1 .set (Tmp .v31 .x , Tmp .v31 .y );
458
455
459
456
ArcBulletData data = new ArcBulletData (z , Tmp .v31 .z , -Tmp .v32 .z );
460
- data .xAccel = Tmp .v32 .x ;
461
- data .yAccel = Tmp .v32 .y ;
457
+ data .accel = Tmp .v32 .len ();
462
458
463
459
Bullet bullet = beginBulletCreate (owner , team , x , y );
464
460
bullet .vel .set (Tmp .v1 );
@@ -542,7 +538,7 @@ public Bullet beginBulletCreate(Entityc owner, Team team, float x, float y){
542
538
}
543
539
544
540
public static class ArcBulletData implements Cloneable {
545
- public float xAccel , yAccel ;
541
+ public float accel ;
546
542
public float lastZ , z , zVel , gravity ;
547
543
public float driftYaw , driftPitch ;
548
544
public ArcBulletType splitFrom ;
@@ -562,7 +558,7 @@ public ArcBulletData(){
562
558
}
563
559
564
560
public void backMove (Bullet b ){
565
- b .vel .sub (xAccel * Time . delta , yAccel * Time .delta );
561
+ b .vel .sub (Tmp . v1 . trns ( b . rotation (), accel * Time .delta ) );
566
562
z -= zVel * Time .delta ;
567
563
zVel += gravity * Time .delta ;
568
564
}
@@ -572,25 +568,22 @@ public void updateLifetime(Bullet b){
572
568
b .lifetime (PMMathf .solve (-0.5f * gravity , zVel , z ) + b .time );
573
569
}
574
570
575
- /** Sets constant acceleration in the x and y directions based on distance to target, initial velocity, and lifetime. */
571
+ /** Sets constant acceleration in based on distance to target, current velocity, and lifetime. */
576
572
public void updateAccel (Bullet b ){
577
573
float life = b .lifetime () - b .time ();
578
- //Calculate accels
579
- float dx = b .aimX - b .x ;
580
- xAccel = (2 * (dx - b .vel .x * life )) / (life * life );
581
- float dy = b .aimY - b .y ;
582
- yAccel = (2 * (dy - b .vel .y * life )) / (life * life );
574
+ float d = Mathf .dst (b .x , b .y , b .aimX , b .aimY );
575
+ accel = (2 * (d - b .vel .len () * life )) / (life * life );
583
576
}
584
577
585
578
/** Sets the bullet's aim pos based on accel, initial velocity, and lifetime */
586
579
public void updateAimPos (Bullet b ){
587
580
float life = b .lifetime () - b .time ();
588
- b .aimX = 0.5f * xAccel * life * life + b .vel .x * life + b .x ;
589
- b .aimY = 0.5f * yAccel * life * life + b .vel .y * life + b .y ;
581
+ b .aimX = 0.5f * xAccel ( b ) * life * life + b .vel .x * life + b .x ;
582
+ b .aimY = 0.5f * yAccel ( b ) * life * life + b .vel .y * life + b .y ;
590
583
}
591
584
592
585
public void update (Bullet b ){
593
- b .vel .add (xAccel * Time . delta , yAccel * Time .delta );
586
+ b .vel .add (Tmp . v1 . trns ( b . rotation (), accel * Time .delta ) );
594
587
lastZ = z ;
595
588
z += zVel * Time .delta ;
596
589
zVel -= gravity * Time .delta ;
@@ -612,12 +605,19 @@ public void update(Bullet b){
612
605
if (needUpdate ) updateAimPos (b );
613
606
}
614
607
615
- public ArcBulletData setAccel (float angle , float a ){
616
- xAccel = Angles .trnsx (angle , a );
617
- yAccel = Angles .trnsy (angle , a );
608
+ public ArcBulletData setAccel (float a ){
609
+ accel = a ;
618
610
return this ;
619
611
}
620
612
613
+ public float xAccel (Bullet b ){
614
+ return accel * Mathf .cosDeg (b .rotation ());
615
+ }
616
+
617
+ public float yAccel (Bullet b ){
618
+ return accel * Mathf .sinDeg (b .rotation ());
619
+ }
620
+
621
621
public ArcBulletData copy (){
622
622
try {
623
623
return (ArcBulletData )clone ();
0 commit comments