Better physics

This commit is contained in:
Anuken
2020-04-30 22:09:42 -04:00
parent 273f4590df
commit 3b340f7164
3 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,7 @@ public class PhysicsProcess implements AsyncProcess{
private Array<PhysicRef> refs = new Array<>(false); private Array<PhysicRef> refs = new Array<>(false);
private BodyDef def; private BodyDef def;
private EntityGroup<? extends Hitboxc> group; private EntityGroup<Unitc> group;
private Filter flying = new Filter(){{ private Filter flying = new Filter(){{
maskBits = categoryBits = 2; maskBits = categoryBits = 2;
}}, ground = new Filter(){{ }}, ground = new Filter(){{
@ -44,17 +44,17 @@ public class PhysicsProcess implements AsyncProcess{
}); });
//find entities without bodies and assign them //find entities without bodies and assign them
for(Hitboxc entity : group){ for(Unitc entity : group){
boolean grounded = ((Flyingc)entity).isGrounded(); boolean grounded = entity.isGrounded();
if(entity.body() == null){ if(entity.body() == null){
//add bodies to entities that have none //add bodies to entities that have none
CircleShape shape = new CircleShape(); CircleShape shape = new CircleShape();
shape.setRadius(entity.hitSize() * 0.46f); shape.setRadius(entity.hitSize() / 2f);
FixtureDef fd = new FixtureDef(); FixtureDef fd = new FixtureDef();
fd.shape = shape; fd.shape = shape;
fd.density = 10.0f; fd.density = 5.0f * entity.mass();
fd.restitution = 0.05f; fd.restitution = 0.05f;
fd.filter.maskBits = fd.filter.categoryBits = (grounded ? ground : flying).maskBits; fd.filter.maskBits = fd.filter.categoryBits = (grounded ? ground : flying).maskBits;
@ -62,7 +62,6 @@ public class PhysicsProcess implements AsyncProcess{
Body body = physics.createBody(def); Body body = physics.createBody(def);
body.createFixture(fd); body.createFixture(fd);
body.setUserData(entity); body.setUserData(entity);
PhysicRef ref = new PhysicRef(entity, body); PhysicRef ref = new PhysicRef(entity, body);
@ -101,7 +100,7 @@ public class PhysicsProcess implements AsyncProcess{
ref.body.setLinearVelocity(ref.velocity); ref.body.setLinearVelocity(ref.velocity);
} }
physics.step(Core.graphics.getDeltaTime(), 3, 3); physics.step(Core.graphics.getDeltaTime(), 8, 8);
//get delta vectors //get delta vectors
for(PhysicRef ref : refs){ for(PhysicRef ref : refs){

View File

@ -89,11 +89,12 @@ public class UnitTypes implements ContentList{
speed = 1f; speed = 1f;
accel = 0.08f; accel = 0.08f;
drag = 0f; drag = 0f;
mass = 2f; mass = 30f;
flying = true; flying = true;
health = 75000; health = 75000;
engineOffset = 40; engineOffset = 40;
engineSize = 7.3f; engineSize = 7.3f;
hitsize = 58f;
weapons.add(new Weapon(){{ weapons.add(new Weapon(){{
y = 1.5f; y = 1.5f;

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=3533846d0009cda47c9416c4cb105b8e79518099 archash=9fc6cd8c90e0665cc3a583879b2007fe29fbc929