mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-20 04:37:31 +07:00
Movement
This commit is contained in:
@ -22,7 +22,7 @@ public class UnitTypes implements ContentList{
|
||||
|
||||
dagger = new UnitDef("dagger"){{
|
||||
speed = 0.2f;
|
||||
drag = 0.4f;
|
||||
drag = 0.2f;
|
||||
hitsize = 8f;
|
||||
mass = 1.75f;
|
||||
health = 130;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
@ -9,6 +10,14 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc
|
||||
|
||||
float baseRotation, walkTime;
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(vel().len() > 0.5f){
|
||||
baseRotation = vel().angle();
|
||||
walkTime += Time.delta()*vel().len()/1f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGroundUnder(){
|
||||
type().drawLegs(this);
|
||||
|
@ -96,6 +96,10 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
|
||||
|
||||
public void unit(Unitc unit){
|
||||
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;
|
||||
if(unit != Nulls.unit){
|
||||
unit.team(team);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
@ -71,6 +73,14 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
return type;
|
||||
}
|
||||
|
||||
public void lookAt(float angle){
|
||||
rotation = Angles.moveToward(rotation, angle, type.rotateSpeed);
|
||||
}
|
||||
|
||||
public void lookAt(Position pos){
|
||||
lookAt(angleTo(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
//apply knockback based on spawns
|
||||
|
@ -153,7 +153,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
//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);
|
||||
if(unit != null){
|
||||
unit.hitbox(Tmp.r1);
|
||||
@ -501,7 +501,8 @@ public class DesktopInput extends InputHandler{
|
||||
float xa = Core.input.axis(Binding.move_x);
|
||||
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();
|
||||
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 Unitc> constructor;
|
||||
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 health = 200f, range = -1;
|
||||
public boolean targetAir = false, targetGround = false;
|
||||
@ -198,7 +198,7 @@ public class UnitDef extends UnlockableContent{
|
||||
public void drawLegs(Legsc unit){
|
||||
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();
|
||||
|
||||
|
Reference in New Issue
Block a user