Low-FPS bullet behavior fixes
This commit is contained in:
@@ -138,9 +138,6 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
public boolean reflectable = true;
|
public boolean reflectable = true;
|
||||||
/** Whether this projectile can be absorbed by shields. */
|
/** Whether this projectile can be absorbed by shields. */
|
||||||
public boolean absorbable = true;
|
public boolean absorbable = true;
|
||||||
/** Whether to move the bullet back depending on delta to fix some delta-time related issues.
|
|
||||||
* Do not change unless you know what you're doing. */
|
|
||||||
public boolean backMove = true;
|
|
||||||
/** If true, the angle param in create is ignored. */
|
/** If true, the angle param in create is ignored. */
|
||||||
public boolean ignoreSpawnAngle = false;
|
public boolean ignoreSpawnAngle = false;
|
||||||
/** Chance for this bullet to be created. */
|
/** Chance for this bullet to be created. */
|
||||||
@@ -928,14 +925,11 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
bullet.aimY = aimY;
|
bullet.aimY = aimY;
|
||||||
|
|
||||||
bullet.initVel(angle, speed * velocityScl * (velocityScaleRandMin != 1f || velocityScaleRandMax != 1f ? Mathf.random(velocityScaleRandMin, velocityScaleRandMax) : 1f));
|
bullet.initVel(angle, speed * velocityScl * (velocityScaleRandMin != 1f || velocityScaleRandMax != 1f ? Mathf.random(velocityScaleRandMin, velocityScaleRandMax) : 1f));
|
||||||
if(backMove){
|
bullet.set(x, y);
|
||||||
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
|
bullet.lastX = x;
|
||||||
}else{
|
bullet.lastY = y;
|
||||||
bullet.set(x, y);
|
|
||||||
}
|
|
||||||
bullet.lifetime = lifetime * lifetimeScl * (lifeScaleRandMin != 1f || lifeScaleRandMax != 1f ? Mathf.random(lifeScaleRandMin, lifeScaleRandMax) : 1f);
|
bullet.lifetime = lifetime * lifetimeScl * (lifeScaleRandMin != 1f || lifeScaleRandMax != 1f ? Mathf.random(lifeScaleRandMin, lifeScaleRandMax) : 1f);
|
||||||
bullet.data = data;
|
bullet.data = data;
|
||||||
bullet.drag = drag;
|
|
||||||
bullet.hitSize = hitSize;
|
bullet.hitSize = hitSize;
|
||||||
bullet.mover = mover;
|
bullet.mover = mover;
|
||||||
bullet.damage = (damage < 0 ? this.damage : damage) * bullet.damageMultiplier();
|
bullet.damage = (damage < 0 ? this.damage : damage) * bullet.damageMultiplier();
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ public class PointBulletType extends BulletType{
|
|||||||
collides = false;
|
collides = false;
|
||||||
reflectable = false;
|
reflectable = false;
|
||||||
keepVelocity = false;
|
keepVelocity = false;
|
||||||
backMove = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
@EntityDef(value = {Bulletc.class}, pooled = true, serialize = false)
|
@EntityDef(value = {Bulletc.class}, pooled = true, serialize = false)
|
||||||
@Component(base = true)
|
@Component(base = true)
|
||||||
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
|
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Bulletc, Timerc{
|
||||||
@Import Team team;
|
@Import Team team;
|
||||||
@Import Entityc owner;
|
@Import Entityc owner;
|
||||||
@Import float x, y, damage, lastX, lastY, time, lifetime;
|
@Import float x, y, damage, lastX, lastY, time, lifetime;
|
||||||
@Import Vec2 vel;
|
|
||||||
|
|
||||||
IntSeq collided = new IntSeq(6);
|
IntSeq collided = new IntSeq(6);
|
||||||
BulletType type;
|
BulletType type;
|
||||||
|
Vec2 vel = new Vec2();
|
||||||
|
|
||||||
Object data;
|
Object data;
|
||||||
float fdata;
|
float fdata;
|
||||||
@@ -39,6 +39,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||||||
|
|
||||||
//setting this variable to true prevents lifetime from decreasing for a frame.
|
//setting this variable to true prevents lifetime from decreasing for a frame.
|
||||||
transient boolean keepAlive;
|
transient boolean keepAlive;
|
||||||
|
transient boolean justSpawned = true;
|
||||||
/** Unlike the owner, the shooter is the original entity that created this bullet. For a second-stage missile, the shooter would be the turret, but the owner would be the last missile stage.*/
|
/** Unlike the owner, the shooter is the original entity that created this bullet. For a second-stage missile, the shooter would be the turret, but the owner would be the last missile stage.*/
|
||||||
transient Entityc shooter;
|
transient Entityc shooter;
|
||||||
transient @Nullable Tile aimTile;
|
transient @Nullable Tile aimTile;
|
||||||
@@ -151,6 +152,15 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
//for one frame, bullets do not move - this is because bullet.update() is called immediately after the weapon updates
|
||||||
|
//if the bullet moved immediately, it would spawn visually offset from the weapon at low FPS values
|
||||||
|
if(!justSpawned){
|
||||||
|
x += vel.x * Time.delta;
|
||||||
|
y += vel.y * Time.delta;
|
||||||
|
vel.scl(Math.max(1f - type.drag * Time.delta, 0));
|
||||||
|
}
|
||||||
|
justSpawned = false;
|
||||||
|
|
||||||
if(mover != null){
|
if(mover != null){
|
||||||
mover.move(self());
|
mover.move(self());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user