Collision engine tweaks, crosshair+bow change

This commit is contained in:
austin 2021-11-05 00:08:12 -04:00
parent a00f423696
commit bb3dae9814
7 changed files with 33 additions and 19 deletions

Binary file not shown.

Binary file not shown.

View File

@ -8,6 +8,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.main.Globals;
import electrosphere.menu.MenuTransition;
@ -16,6 +17,7 @@ import electrosphere.util.Utilities;
import java.util.HashMap;
import java.util.List;
import org.joml.Vector2f;
import org.joml.Vector3d;
import org.joml.Vector3f;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.glfw.GLFW.glfwGetCursorPos;
@ -376,6 +378,7 @@ public class ControlHandler {
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isState() == true){
Entity bow = ItemUtils.spawnBasicItem("Bow");
EntityUtils.getPosition(bow).set(1, 5, 2);
CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));
}
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(false);
}

View File

@ -589,12 +589,12 @@ public class LoadingThread extends Thread {
// //attach ai to evil goblin
// MindlessAttacker.attachToCreature(goblin);
// StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
Entity bow = ItemUtils.spawnBasicItem("Bow");
EntityUtils.getPosition(bow).set(1, 1, 2);
// NavMeshPathfinder.navigatePointToPointInMesh(Globals.navMeshManager.getMeshes().get(0), new Vector3d(10,0,5), new Vector3d(5,0,10));
// NavMeshPathfinder.navigatePointToPointInMesh(G*lobals.navMeshManager.getMeshes().get(0), new Vector3d(10,0,5), new Vector3d(5,0,10));
// NavMesh mesh = new NavMesh();
// NavCube cube = new NavCube(5,0,0,10,5,5);

View File

@ -31,7 +31,7 @@ public class GravityTree {
Entity parent;
float gravityVelocity = 0;
float gravityAccel = 0.01f;
float gravityAccel = 0.0002f;
CollisionObject body;
Collidable collidable;

View File

@ -37,30 +37,41 @@ public class CollidableTree {
Vector3d offsetVector = new Vector3d();
Vector3d newPosition = new Vector3d(position);
javax.vecmath.Matrix4f bodyTransformMatrix;
//have we hit a terrain impulse?
boolean hitTerrain = false;
//handle impulses
for(Impulse impulse : collidable.getImpulses()){
// collidable.getImpulses().remove(impulse);
Vector3d impulseForce = new Vector3d(impulse.getDirection()).mul(impulse.getForce());
// if(impulse.type.matches(Collidable.TYPE_TERRAIN)){
if(impulse.type.matches(Collidable.TYPE_TERRAIN)){
hitTerrain = true;
// System.out.println("Impulse force: " + impulseForce);
// System.out.println("Position: " + position);
// }
// if(impulse.type.matches(Collidable.TYPE_ITEM)){
// if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
// ((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
// }
// }
// if(impulse.type.matches(Collidable.TYPE_CREATURE)){
// if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
// ((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
// }
// }
}
if(impulse.type.matches(Collidable.TYPE_ITEM)){
if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
}
}
if(impulse.type.matches(Collidable.TYPE_CREATURE)){
// System.out.println(System.currentTimeMillis() + " creature hit!");
if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
}
}
// if(impulse.type.matches("movement")){
// System.out.println("Impulse force: " + impulseForce);
// }
offsetVector.add(impulseForce);
}
//the reasoning here is that if we have something above something else and it's pushing it into the terrain,
//we should instead just not push into terrain and push along terrain
if(hitTerrain && offsetVector.y < 0){
offsetVector.y = 0;
}
//make sure we're in a valid (World bounds) position
newPosition.add(offsetVector);
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){

View File

@ -129,9 +129,9 @@ public class CollisionEngine {
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
break;
case Collidable.TYPE_STRUCTURE:
float realMag = 1f/(float)Math.pow(0.1, magnitude);
// float realMag = 1f/(float)Math.pow(0.1, magnitude);
// System.out.println(normal + " - " + realMag);
receiver.addImpulse(new Impulse(normal, realMag, Collidable.TYPE_STRUCTURE));
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_STRUCTURE));
// System.out.println("Structure-creature collision");
break;
case Collidable.TYPE_ITEM:
@ -151,9 +151,9 @@ public class CollisionEngine {
receiver.addImpulse(new Impulse(normal, Math.min(magnitude * 0.5,0.5), Collidable.TYPE_CREATURE));
break;
case Collidable.TYPE_STRUCTURE:
float realMag = 1f/(float)Math.pow(0.1, magnitude);
// float realMag = 1f/(float)Math.pow(0.1, magnitude);
// System.out.println(normal + " - " + realMag);
receiver.addImpulse(new Impulse(normal, realMag, Collidable.TYPE_STRUCTURE));
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_STRUCTURE));
// System.out.println("Structure-creature collision");
break;
case Collidable.TYPE_ITEM: