mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-20 12:47:37 +07:00
Fixed clientside physics jitter
This commit is contained in:
@ -24,6 +24,7 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
@Override
|
@Override
|
||||||
public void begin(){
|
public void begin(){
|
||||||
if(physics == null) return;
|
if(physics == null) return;
|
||||||
|
boolean local = !Vars.net.client();
|
||||||
|
|
||||||
//remove stale entities
|
//remove stale entities
|
||||||
refs.removeAll(ref -> {
|
refs.removeAll(ref -> {
|
||||||
@ -62,6 +63,7 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
entity.isGrounded() ? layerGround : layerFlying;
|
entity.isGrounded() ? layerGround : layerFlying;
|
||||||
ref.x = entity.x;
|
ref.x = entity.x;
|
||||||
ref.y = entity.y;
|
ref.y = entity.y;
|
||||||
|
ref.body.local = local || entity.isLocal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,6 +158,10 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
|
|
||||||
for(int i = 0; i < bodies.size; i++){
|
for(int i = 0; i < bodies.size; i++){
|
||||||
PhysicsBody body = bodies.items[i];
|
PhysicsBody body = bodies.items[i];
|
||||||
|
|
||||||
|
//for clients, the only body that collides is the local one; all other physics simulations are handled by the server.
|
||||||
|
if(!body.local) continue;
|
||||||
|
|
||||||
body.hitbox(rect);
|
body.hitbox(rect);
|
||||||
|
|
||||||
seq.size = 0;
|
seq.size = 0;
|
||||||
@ -174,10 +180,14 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
float ms = body.mass + other.mass;
|
float ms = body.mass + other.mass;
|
||||||
float m1 = other.mass / ms, m2 = body.mass / ms;
|
float m1 = other.mass / ms, m2 = body.mass / ms;
|
||||||
|
|
||||||
|
//first body is always local due to guard check above
|
||||||
body.x += vec.x * m1 / scl;
|
body.x += vec.x * m1 / scl;
|
||||||
body.y += vec.y * m1 / scl;
|
body.y += vec.y * m1 / scl;
|
||||||
other.x -= vec.x * m2 / scl;
|
|
||||||
other.y -= vec.y * m2 / scl;
|
if(other.local){
|
||||||
|
other.x -= vec.x * m2 / scl;
|
||||||
|
other.y -= vec.y * m2 / scl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body.collided = true;
|
body.collided = true;
|
||||||
@ -187,7 +197,7 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
public static class PhysicsBody implements QuadTreeObject{
|
public static class PhysicsBody implements QuadTreeObject{
|
||||||
public float x, y, radius, mass;
|
public float x, y, radius, mass;
|
||||||
public int layer = 0;
|
public int layer = 0;
|
||||||
public boolean collided = false;
|
public boolean collided = false, local = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hitbox(Rect out){
|
public void hitbox(Rect out){
|
||||||
|
@ -10,4 +10,4 @@ kapt.include.compile.classpath=false
|
|||||||
kotlin.stdlib.default.dependency=false
|
kotlin.stdlib.default.dependency=false
|
||||||
#needed for android compilation
|
#needed for android compilation
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
archash=45d17a1ade5b67b1e663785592d25f833feeecaf
|
archash=1dd6c22dad3981525760254900e91634e7513714
|
||||||
|
Reference in New Issue
Block a user