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