Small ai fixes

This commit is contained in:
austin 2021-11-27 18:25:06 -05:00
parent 96d2fdf474
commit d3197547d0
2 changed files with 16 additions and 1 deletions

View File

@ -101,7 +101,7 @@ public class GroundMovementTree {
Vector3d position = EntityUtils.getPosition(parent);
Vector3d movementVector = CreatureUtils.getMovementVector(parent);
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z)).normalize();
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,0,(float)movementVector.z)).normalize();
Quaternionf rotation = EntityUtils.getRotation(parent);
//parse attached network messages

View File

@ -10,6 +10,10 @@ import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.ai.AI;
import electrosphere.main.Globals;
import org.joml.Vector3f;
import org.joml.Quaternionf;
import org.joml.Vector3d;
/**
@ -60,6 +64,7 @@ public class OpportunisticAttacker extends AI {
if(target != null){
if(inAttackRange()){
if(hasWeapon()){
faceTarget();
attack();
} else {
if(weaponInRange()){
@ -71,6 +76,7 @@ public class OpportunisticAttacker extends AI {
} else {
if(inAggroRange()){
if(hasWeapon()){
faceTarget();
moveToTarget();
} else {
if(weaponInRange()){
@ -243,6 +249,15 @@ public class OpportunisticAttacker extends AI {
}
}
void faceTarget(){
Vector3d position = EntityUtils.getPosition(character);
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d movementVector = new Vector3d(targetPosition).sub(position).normalize();
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,0,(float)movementVector.z)).normalize();
CreatureUtils.setMovementVector(character, movementVector);
EntityUtils.getRotation(character).set(movementQuaternion);
}
void setGoal(OpportunisticAttackerGoal goal){
this.goal = goal;
switch(goal){