Rotation half fixed
This commit is contained in:
parent
adbfa34350
commit
347a269c4d
1 changed files with 51 additions and 22 deletions
|
|
@ -72,6 +72,7 @@ public abstract class Unit extends GameEntity{
|
|||
}
|
||||
oldPos = new Vector2i(x, y);
|
||||
InGameState.getMap().setPos(this, x, y);
|
||||
System.out.println(oldPos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,26 +98,54 @@ public abstract class Unit extends GameEntity{
|
|||
getSelection().setValue(getLife());
|
||||
|
||||
if(moveTo != null) {
|
||||
Vector2i moveVect = Map.getPosByPixel(moveTo.getX(), moveTo.getY());
|
||||
Vector2i currentVect = Map.getPosByPixel(unitNode.getLocation().getX(), unitNode.getLocation().getY());
|
||||
Vector3f lastRotation = new Vector3f(0, 0, 0);
|
||||
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
||||
Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
|
||||
|
||||
int moveXminus = moveVect.getX()-currentVect.getX();
|
||||
int moveYminus = moveVect.getY()-currentVect.getY();
|
||||
System.out.println(moveVect.getY());
|
||||
System.out.println(currentVect);
|
||||
|
||||
float divideY = (moveVect.getY()+1)/(currentVect.getY()+1);
|
||||
float divideX = (moveVect.getX()+1)/(currentVect.getX()+1);
|
||||
|
||||
//The rotation animation is done here.
|
||||
if(moveVect.getX() < currentVect.getX()) {
|
||||
if(moveVect.getX() < currentVect.getX() && divideY==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 90));
|
||||
}
|
||||
|
||||
if(moveVect.getX() > currentVect.getX()){
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
|
||||
}
|
||||
|
||||
if(moveVect.getY() < currentVect.getY()){
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
|
||||
}
|
||||
|
||||
if(moveVect.getY() > currentVect.getY()) {
|
||||
}
|
||||
if(moveVect.getY() > currentVect.getY() && divideX==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if(moveVect.getX() > currentVect.getX() && divideY==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
|
||||
}
|
||||
|
||||
if(moveVect.getY() < currentVect.getY() && divideX==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
|
||||
}
|
||||
|
||||
//Diagonally.
|
||||
if(moveVect.getX() > currentVect.getX() && moveVect.getY() > currentVect.getY()
|
||||
&& moveXminus>=2 && moveYminus>=2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -45));
|
||||
}
|
||||
|
||||
if(moveVect.getX() < currentVect.getX() && moveVect.getY() < currentVect.getY()
|
||||
&& moveXminus<=-2 && moveYminus<=-2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 135));
|
||||
}
|
||||
|
||||
if(moveVect.getX() > currentVect.getX() && moveVect.getY() < currentVect.getY()
|
||||
&& moveXminus>=2 && moveYminus<=-2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -135));
|
||||
}
|
||||
|
||||
if(moveVect.getX() < currentVect.getX() && moveVect.getY() > currentVect.getY()
|
||||
&& moveXminus<=-2 && moveYminus>=2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 45));
|
||||
}
|
||||
|
||||
//System.out.println(unitNode.get("Tank").getRotation());
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue