More physics tweaks
This commit is contained in:
parent
bbbeb0f848
commit
c5834a0bca
@ -213,10 +213,10 @@
|
||||
"physicsObject" : {
|
||||
"type" : "CYLINDER",
|
||||
"dimension1" : 0.1,
|
||||
"dimension2" : 0.1,
|
||||
"dimension2" : 0.2,
|
||||
"dimension3" : 0.1,
|
||||
"offsetX" : 0,
|
||||
"offsetY" : 0.1,
|
||||
"offsetY" : 0.2,
|
||||
"offsetZ" : 0
|
||||
},
|
||||
"attackMoves" : [
|
||||
|
||||
@ -67,7 +67,7 @@ public class GravityTree {
|
||||
}
|
||||
|
||||
static final float gravityConstant = 0.2f;
|
||||
static final float linearDamping = 0.02f;
|
||||
static final float linearDamping = 0.1f;
|
||||
|
||||
public void simulate(float deltaTime){
|
||||
float velocity = CreatureUtils.getVelocity(parent);
|
||||
@ -107,6 +107,9 @@ public class GravityTree {
|
||||
case ACTIVE:
|
||||
if(hadGroundCollision()){
|
||||
state = GravityTreeState.NOT_ACTIVE;
|
||||
if(!hadStructureCollision()){
|
||||
position.set(new Vector3f(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z));
|
||||
}
|
||||
} else {
|
||||
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||
Vector3f newGravityPos = new Vector3f(position.x,position.y - gravityDif,position.z);
|
||||
@ -135,6 +138,17 @@ public class GravityTree {
|
||||
networkMessageQueue.add(networkMessage);
|
||||
}
|
||||
|
||||
public boolean hadStructureCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_STRUCTURE)){
|
||||
rVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public boolean hadGroundCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
|
||||
@ -146,7 +146,9 @@ public class MovementTree {
|
||||
//handle impulses
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
// collidable.getImpulses().remove(impulse);
|
||||
position.add(impulse.direction.mul(impulse.force));
|
||||
Vector3f impulseForce = new Vector3f(impulse.direction).mul(impulse.force);
|
||||
// System.out.println("Impulse force: " + impulseForce);
|
||||
position.add(impulseForce);
|
||||
}
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
|
||||
@ -95,7 +95,7 @@ public class CollisionEngine {
|
||||
if (contactPoint.getDistance() < 0.0f) {
|
||||
magnitude = contactPoint.getDistance();
|
||||
//linear dampen
|
||||
magnitude = magnitude * (float)Math.pow(1.0f - linearDamping,deltaTime * 2) * deltaTime * 8;
|
||||
magnitude = magnitude * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||
hit = true;
|
||||
normal = new Vector3f(contactPoint.normalWorldOnB.x,contactPoint.normalWorldOnB.y,contactPoint.normalWorldOnB.z);
|
||||
break;
|
||||
@ -124,12 +124,13 @@ public class CollisionEngine {
|
||||
switch(impactor.getType()){
|
||||
case Collidable.TYPE_TERRAIN:
|
||||
// System.out.println("Terrain-creature collision: " + normal + " mag:" + realMagnitude);
|
||||
receiver.addImpulse(new Impulse(new Vector3f(0,1.0f,0), -1.0f * magnitude, Collidable.TYPE_TERRAIN));
|
||||
receiver.addImpulse(new Impulse(new Vector3f(0,normal.y,0), -magnitude, Collidable.TYPE_TERRAIN));
|
||||
break;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
System.out.println(normal + " - " + magnitude);
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
|
||||
@ -94,7 +94,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
System.exit(1);
|
||||
}
|
||||
//spawn player in world
|
||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Goblin");
|
||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Human");
|
||||
playerCharacterID = newPlayerCharacter.getId();
|
||||
CreatureUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,3,Globals.spawnPoint.z));
|
||||
//spawn player sword
|
||||
|
||||
Loading…
Reference in New Issue
Block a user