v6 rotational walking :D
This commit is contained in:
1 parent
054cfb6d72
commit
8630ef0753
9 files changed
+145
-12
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -24,7 +24,7 @@ public class Leg : MonoBehaviour {
|
||||
public double translateZ = 0;
|
||||
|
||||
public GameObject pointShouldBe;
|
||||
public Vector3 pos = new Vector3(0, 0, 0);
|
||||
//public Vector3 pos = new Vector3(0, 0, 0);
|
||||
|
||||
public int startServo = -1;
|
||||
|
||||
@@ -99,6 +99,16 @@ public class Leg : MonoBehaviour {
|
||||
pointShouldBe.transform.localPosition = foot.pos;
|
||||
}
|
||||
|
||||
public Vector3 getWorldPos()
|
||||
{
|
||||
return point + new Vector3((float)translateX, (float)translateY, (float)translateZ);
|
||||
}
|
||||
|
||||
public void setWorldPos(Vector3 pos)
|
||||
{
|
||||
this.point = pos - new Vector3((float)translateX, (float)translateY, (float)translateZ);
|
||||
}
|
||||
|
||||
public static float Remap(float value, float from1, float to1, float from2, float to2)
|
||||
{
|
||||
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
|
||||
|
||||
Binary file not shown.
@@ -35,9 +35,16 @@ public class Serial {
|
||||
{
|
||||
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
|
||||
|
||||
serialPort.Open();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.DiscardInBuffer();
|
||||
try
|
||||
{
|
||||
serialPort.Open();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.DiscardInBuffer();
|
||||
}
|
||||
catch
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (serialPort is SerialPort)
|
||||
|
||||
@@ -47,8 +47,8 @@ public class Walk : MonoBehaviour
|
||||
|
||||
new step(new Vector3(0, 0, 0), false), // rest
|
||||
|
||||
new step(new Vector3(0, 2, 0), true),
|
||||
new step(new Vector3(-1, 0, 0), false),
|
||||
new step(new Vector3(0, 2, 0), false),
|
||||
new step(new Vector3(-1, 0, 0), true),
|
||||
};
|
||||
|
||||
public int st = 5;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Walk2 : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> legs = new List<GameObject>();
|
||||
private List<Vector3> legsInitial = new List<Vector3>();
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
for (int index = 0; index < legs.Count; ++index)
|
||||
{
|
||||
legsInitial.Add(legs[index].GetComponent<Leg>().point);
|
||||
}
|
||||
}
|
||||
|
||||
struct step
|
||||
{
|
||||
public float rotation;
|
||||
public float height;
|
||||
public bool inAir;
|
||||
|
||||
public step(float r, float h, bool i)
|
||||
{
|
||||
rotation = r;
|
||||
height = h;
|
||||
inAir = i;
|
||||
}
|
||||
}
|
||||
|
||||
// 1, 3, 5 -= 3
|
||||
|
||||
int offset(int i, int offset, int max)
|
||||
{
|
||||
return i - offset < 0 ? (max - (offset - i)) : i - offset;
|
||||
}
|
||||
|
||||
step[] s = {
|
||||
new step(-1, 0, false),
|
||||
|
||||
new step(0, -2, false),
|
||||
|
||||
new step(0, 0, false), // rest
|
||||
|
||||
new step(1, 0, false),
|
||||
new step(1, 0, false),
|
||||
|
||||
new step(0, 0, false), // rest
|
||||
|
||||
new step(0, 2, false),
|
||||
new step(-1, 0, true),
|
||||
};
|
||||
|
||||
public int st = 5;
|
||||
public int speed2 = 30;
|
||||
int speed = 10;
|
||||
|
||||
public float rotation = 0;
|
||||
|
||||
int size = 8;
|
||||
|
||||
//public float walkspeed = 1;
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (speed <= 0)
|
||||
{
|
||||
if (st >= size-1)
|
||||
st = 0;
|
||||
else
|
||||
st++;
|
||||
|
||||
for (int index = 0; index < legs.Count; ++index)
|
||||
{
|
||||
int t = st;
|
||||
if (index == 1 || index == 3 || index == 5)
|
||||
{
|
||||
t = offset(st, 4, size);
|
||||
}
|
||||
|
||||
if (s[t].inAir == false)
|
||||
{
|
||||
Vector3 n = legs[index].GetComponent<Leg>().getWorldPos();
|
||||
n = Quaternion.Euler(0, rotation * s[t].rotation, 0) * n;
|
||||
n.y += s[t].height;
|
||||
// rotate x,y around rotation.
|
||||
legs[index].GetComponent<Leg>().setWorldPos(n);
|
||||
}
|
||||
else
|
||||
{
|
||||
legs[index].GetComponent<Leg>().point = legsInitial[index] + new Vector3(0, s[t].height, 0);
|
||||
}
|
||||
}
|
||||
|
||||
speed = speed2;
|
||||
}
|
||||
else
|
||||
speed--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91e6f3895f276d94da1803128e6290e0
|
||||
timeCreated: 1542229569
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user