kinematic lerp

This commit is contained in:
Anuken 2020-06-08 11:45:43 -04:00
parent 427cf8e594
commit 1f905790e7
8 changed files with 18 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 599 B

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 618 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 KiB

After

Width:  |  Height:  |  Size: 856 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

@ -214,7 +214,6 @@ public class UnitTypes implements ContentList{
legLength = 9f;
legTrns = 0.6f;
legMoveSpace = 1.4f;
legBend = 1f;
weapons.add(new Weapon("eruption"){{
shootY = 3f;
@ -250,8 +249,9 @@ public class UnitTypes implements ContentList{
legBaseOffset = 10f;
landShake = 2f;
legSpeed = 0.1f;
legBend = 0.3f;
legLengthScl = 1f;
rippleScale = 2f;
legSpeed = 0.2f;
for(boolean b : Mathf.booleans){
weapons.add(

View File

@ -8,6 +8,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.blocks.environment.*;
@ -55,18 +56,22 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc, Elevatio
float trns = moveSpace * 0.85f * type.legTrns;
//rotation + offset vector
Vec2 moveOffset = Tmp.v4.trns(rot, trns).add(x, y);
Vec2 moveOffset = Tmp.v4.trns(rot, trns);
for(int i = 0; i < legs.length; i++){
float dstRot = legAngle(rot, i);
Vec2 baseOffset = Tmp.v5.trns(dstRot, type.legBaseOffset).add(moveOffset);
float rot2 = Angles.moveToward(dstRot, rot + (Angles.angleDist(dstRot, rot) < 90f ? 180f : 0), type.legBend * 360f / legs.length / 4f);
Vec2 baseOffset = Tmp.v5.trns(dstRot, type.legBaseOffset).add(x, y);
Leg l = legs[i];
float stageF = (totalLength + i*type.legPairOffset) / moveSpace;
int stage = (int)stageF;
int group = stage % div;
boolean move = i % div == group;
boolean side = i < legs.length/2;
//back legs have reversed directions
boolean backLeg = Math.abs((i + 0.5f) - legs.length/2f) <= 0.501f;
if(backLeg) side = !side;
l.moving = move;
l.stage = stageF % 1f;
@ -91,9 +96,13 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc, Elevatio
}
//leg destination
Vec2 legDest = Tmp.v1.trns(dstRot, legLength).add(baseOffset);
Vec2 legDest = Tmp.v1.trns(dstRot, legLength * type.legLengthScl).add(baseOffset).add(moveOffset);
//join destination
Vec2 jointDest = Tmp.v2.trns(rot2, legLength / 2f + type.legBaseOffset).add(moveOffset);
Vec2 jointDest = Tmp.v2;//.trns(rot2, legLength / 2f + type.legBaseOffset).add(moveOffset);
InverseKinematics.solve(legLength/2f, legLength/2f, Tmp.v6.set(l.base).sub(baseOffset), side, jointDest);
jointDest.add(baseOffset);
//lerp between kinematic and linear
jointDest.lerp(Tmp.v6.set(baseOffset).lerp(l.base, 0.5f), 1f - type.kinematicScl);
if(move){
float moveFract = stageF % 1f;

View File

@ -5,7 +5,7 @@ import arc.math.geom.*;
public class InverseKinematics{
private static final Vec2[] mat1 = {new Vec2(), new Vec2()}, mat2 = {new Vec2(), new Vec2()};
private static final Vec2 temp = new Vec2(), temp2 = new Vec2(), at1 = new Vec2(), at2 = new Vec2();
private static final Vec2 temp = new Vec2(), temp2 = new Vec2(), at1 = new Vec2();
static public boolean solve(float lengthA, float lengthB, Vec2 end, boolean side, Vec2 result){
at1.set(end).rotate(side ? 1 : -1).setLength(lengthA + lengthB).add(end.x / 2f, end.y / 2f);

View File

@ -46,7 +46,7 @@ public class UnitType extends UnlockableContent{
//TODO document
public int legCount = 4, legGroupSize = 2;
public float legLength = 10f, legSpeed = 0.1f, legTrns = 1f, legBaseOffset = 0f, legMoveSpace = 1f, legExtension = 0, legPairOffset = 0, legBend = 0f;
public float legLength = 10f, legSpeed = 0.1f, legTrns = 1f, legBaseOffset = 0f, legMoveSpace = 1f, legExtension = 0, legPairOffset = 0, legLengthScl = 1f, kinematicScl = 1f;
public int itemCapacity = 30;
public int drillTier = -1;