v5 ITS ALIVE, IT WALKS!
This commit is contained in:
1 parent
9dcf9a6190
commit
054cfb6d72
8 files changed
+150
-31
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -81,9 +81,9 @@ public class RotationControl : MonoBehaviour
|
||||
//rotation.y = r2.update();
|
||||
//rotation.z = r3.update();
|
||||
|
||||
transformation.x = r4.update();
|
||||
//transformation.x = r4.update();
|
||||
//transformation.y = r5.update();
|
||||
transformation.z = r6.update();
|
||||
//transformation.z = r6.update();
|
||||
|
||||
/*transformation2.x = r7.update();
|
||||
transformation2.y = r8.update();
|
||||
|
||||
@@ -23,42 +23,47 @@ public class Serial {
|
||||
}
|
||||
}
|
||||
|
||||
public bool enabled = false;
|
||||
|
||||
SerialPort serialPort;
|
||||
|
||||
public void send(int start, int a, int b, int c)
|
||||
{
|
||||
if (serialPort == null)
|
||||
if (enabled)
|
||||
{
|
||||
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
|
||||
if (serialPort == null)
|
||||
{
|
||||
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
|
||||
|
||||
serialPort.Open();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.DiscardInBuffer();
|
||||
}
|
||||
serialPort.Open();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.DiscardInBuffer();
|
||||
}
|
||||
|
||||
if (serialPort is SerialPort)
|
||||
{
|
||||
if (serialPort is SerialPort)
|
||||
{
|
||||
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(a.ToString());
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(a.ToString());
|
||||
|
||||
start++;
|
||||
start++;
|
||||
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(b.ToString());
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(b.ToString());
|
||||
|
||||
start++;
|
||||
start++;
|
||||
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(c.ToString());
|
||||
serialPort.Write(" #");
|
||||
serialPort.Write(start.ToString());
|
||||
serialPort.Write(" P");
|
||||
serialPort.Write(c.ToString());
|
||||
|
||||
serialPort.Write(" \r");
|
||||
serialPort.Write(" \r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Walk : 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 Vector3 pos;
|
||||
public bool inAir;
|
||||
|
||||
public step(Vector3 p, bool i)
|
||||
{
|
||||
pos = p;
|
||||
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(new Vector3(-1, 0, 0), false),
|
||||
|
||||
new step(new Vector3(0, -2, 0), false),
|
||||
|
||||
new step(new Vector3(0, 0, 0), false), // rest
|
||||
|
||||
new step(new Vector3(1, 0, 0), false),
|
||||
new step(new Vector3(1, 0, 0), false),
|
||||
|
||||
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),
|
||||
};
|
||||
|
||||
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 t2 = s[t].pos;
|
||||
t2.x *= walkspeed;
|
||||
|
||||
// rotate x,y around rotation.
|
||||
legs[index].GetComponent<Leg>().point += Quaternion.Euler(0, rotation, 0) * t2;
|
||||
}
|
||||
else
|
||||
{
|
||||
legs[index].GetComponent<Leg>().point = legsInitial[index] + s[t].pos;
|
||||
}
|
||||
}
|
||||
|
||||
speed = speed2;
|
||||
}
|
||||
else
|
||||
speed--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62866dc69f17c5f40a7ec527e34e82f1
|
||||
timeCreated: 1542141752
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user