Movement
This commit is contained in:
@@ -22,7 +22,7 @@ public class UnitTypes implements ContentList{
|
|||||||
|
|
||||||
dagger = new UnitDef("dagger"){{
|
dagger = new UnitDef("dagger"){{
|
||||||
speed = 0.2f;
|
speed = 0.2f;
|
||||||
drag = 0.4f;
|
drag = 0.2f;
|
||||||
hitsize = 8f;
|
hitsize = 8f;
|
||||||
mass = 1.75f;
|
mass = 1.75f;
|
||||||
health = 130;
|
health = 130;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.entities.def;
|
package mindustry.entities.def;
|
||||||
|
|
||||||
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
@@ -9,6 +10,14 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc
|
|||||||
|
|
||||||
float baseRotation, walkTime;
|
float baseRotation, walkTime;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(){
|
||||||
|
if(vel().len() > 0.5f){
|
||||||
|
baseRotation = vel().angle();
|
||||||
|
walkTime += Time.delta()*vel().len()/1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGroundUnder(){
|
public void drawGroundUnder(){
|
||||||
type().drawLegs(this);
|
type().drawLegs(this);
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
|
|||||||
|
|
||||||
public void unit(Unitc unit){
|
public void unit(Unitc unit){
|
||||||
if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead.");
|
if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead.");
|
||||||
|
if(this.unit != Nulls.unit){
|
||||||
|
//un-control the old unit
|
||||||
|
this.unit.controller(this.unit.type().createController());
|
||||||
|
}
|
||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
if(unit != Nulls.unit){
|
if(unit != Nulls.unit){
|
||||||
unit.team(team);
|
unit.team(team);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package mindustry.entities.def;
|
package mindustry.entities.def;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.math.*;
|
||||||
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
@@ -71,6 +73,14 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void lookAt(float angle){
|
||||||
|
rotation = Angles.moveToward(rotation, angle, type.rotateSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lookAt(Position pos){
|
||||||
|
lookAt(angleTo(pos));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
//apply knockback based on spawns
|
//apply knockback based on spawns
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove: debug unit possession
|
//TODO remove: debug unit possession
|
||||||
if(player.dead() && Core.input.keyTap(Binding.select)){
|
if(Core.input.keyTap(Binding.select)){
|
||||||
Unitc unit = Units.closest(state.rules.defaultTeam, Core.input.mouseWorld().x, Core.input.mouseWorld().y, 40f, u -> true);
|
Unitc unit = Units.closest(state.rules.defaultTeam, Core.input.mouseWorld().x, Core.input.mouseWorld().y, 40f, u -> true);
|
||||||
if(unit != null){
|
if(unit != null){
|
||||||
unit.hitbox(Tmp.r1);
|
unit.hitbox(Tmp.r1);
|
||||||
@@ -501,7 +501,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
float xa = Core.input.axis(Binding.move_x);
|
float xa = Core.input.axis(Binding.move_x);
|
||||||
float ya = Core.input.axis(Binding.move_y);
|
float ya = Core.input.axis(Binding.move_y);
|
||||||
|
|
||||||
unit.vel().add(speed * xa, speed * ya);
|
unit.vel().add(Tmp.v1.set(speed * xa, speed * ya).limit(speed));
|
||||||
|
unit.lookAt(Angles.mouseAngle(unit.x(), unit.y()));
|
||||||
/*
|
/*
|
||||||
Tile tile = unit.tileOn();
|
Tile tile = unit.tileOn();
|
||||||
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
|
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class UnitDef extends UnlockableContent{
|
|||||||
public @NonNull Prov<? extends UnitController> defaultController = AIController::new;
|
public @NonNull Prov<? extends UnitController> defaultController = AIController::new;
|
||||||
public @NonNull Prov<? extends Unitc> constructor;
|
public @NonNull Prov<? extends Unitc> constructor;
|
||||||
public boolean flying;
|
public boolean flying;
|
||||||
public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 0.2f, baseRotateSpeed = 0.1f;
|
public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 10f, baseRotateSpeed = 0.1f;
|
||||||
public float drag = 0.3f, mass = 1f, accel = 0.1f;
|
public float drag = 0.3f, mass = 1f, accel = 0.1f;
|
||||||
public float health = 200f, range = -1;
|
public float health = 200f, range = -1;
|
||||||
public boolean targetAir = false, targetGround = false;
|
public boolean targetAir = false, targetGround = false;
|
||||||
@@ -198,7 +198,7 @@ public class UnitDef extends UnlockableContent{
|
|||||||
public void drawLegs(Legsc unit){
|
public void drawLegs(Legsc unit){
|
||||||
Draw.mixcol(Color.white, unit.hitAlpha());
|
Draw.mixcol(Color.white, unit.hitAlpha());
|
||||||
|
|
||||||
float ft = Mathf.sin(unit.walkTime() * unit.vel().len() * 5f, 6f, 2f + unit.hitSize() / 15f);
|
float ft = Mathf.sin(unit.walkTime(), 6f, 2f + unit.hitSize() / 15f);
|
||||||
|
|
||||||
Floor floor = unit.floorOn();
|
Floor floor = unit.floorOn();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user