fix problem in returning to home

This commit is contained in:
2018-11-15 16:37:54 +01:00
parent bf92632485
commit f2b7d27911
6 changed files with 47 additions and 49 deletions
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -48740,7 +48740,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
transformation: {x: 0, y: 2, z: 0}
transformation2: {x: 0, y: 0, z: 0}
rotation: {x: -1, y: 0, z: 2, w: 0}
rotation: {x: 0, y: 0, z: 0, w: 0}
rotation2:
- {fileID: 636309705}
- {fileID: 596626244}
@@ -48756,7 +48756,7 @@ MonoBehaviour:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 311513960}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62866dc69f17c5f40a7ec527e34e82f1, type: 3}
m_Name:
@@ -48769,7 +48769,7 @@ MonoBehaviour:
- {fileID: 1772413224}
- {fileID: 210611261}
st: 5
speed2: 30
speed2: 1
rotation: 0
walkspeed: 1.5
--- !u!114 &311513964
@@ -48791,7 +48791,7 @@ MonoBehaviour:
- {fileID: 1772413224}
- {fileID: 210611261}
st: 5
speed2: 20
speed2: 1
rotation: 5
--- !u!1 &311874317
GameObject:
+9 -19
View File
@@ -28,8 +28,6 @@ public class Serial {
SerialPort serialPort;
public void send(int start, int a, int b, int c)
{
if (enabled)
{
if (serialPort == null)
{
@@ -40,6 +38,8 @@ public class Serial {
serialPort.Open();
serialPort.DiscardOutBuffer();
serialPort.DiscardInBuffer();
enabled = true;
}
catch
{
@@ -47,29 +47,19 @@ public class Serial {
}
}
if (enabled)
{
if (serialPort is SerialPort)
{
serialPort.Write(" #");
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(a.ToString());
string send = " #" + start.ToString() + " P" + a.ToString();
start++;
serialPort.Write(" #");
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(b.ToString());
send = send + " #" + start.ToString() + " P" + b.ToString();
start++;
send = send + " #" + start.ToString() + " P" + c.ToString();
serialPort.Write(" #");
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(c.ToString());
send = send + " \r";
serialPort.Write(" \r");
serialPort.Write(send);
}
}
}
+2 -5
View File
@@ -92,11 +92,8 @@ public class Walk : MonoBehaviour
}
else
{
Vector3 t2 = s[t].pos;
t2.x *= walkspeed;
// rotate x,y around rotation.
step2[index] = (Quaternion.Euler(0, rotation, 0) * t2) / speed2;
Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent<Leg>().point;
step2[index] = t2 / speed2;
}
}
+13 -2
View File
@@ -15,6 +15,7 @@ public class Walk2 : MonoBehaviour
legsInitial.Add(legs[index].GetComponent<Leg>().point);
step2.Add(0);
step3.Add(0);
step4.Add(new Vector3(0, 0, 0));
}
}
@@ -66,6 +67,7 @@ public class Walk2 : MonoBehaviour
//public float walkspeed = 1;
private List<float> step2 = new List<float>();
private List<float> step3 = new List<float>();
private List<Vector3> step4 = new List<Vector3>();
// Update is called once per frame
void FixedUpdate()
@@ -89,11 +91,12 @@ public class Walk2 : MonoBehaviour
{
step2[index] = (rotation * s[t].rotation) / speed2;
step3[index] = s[t].height / speed2;
step4[index] = new Vector3(0, 0, 0);
}
else
{
step2[index] = (rotation * s[t].rotation) / speed2;
step3[index] = s[t].height / speed2;
Vector3 t2 = legsInitial[index] - legs[index].GetComponent<Leg>().point;
step4[index] = t2 / speed2;
}
}
@@ -109,6 +112,8 @@ public class Walk2 : MonoBehaviour
void makestep()
{
for (int index = 0; index < legs.Count; ++index)
{
if (step4[index] == new Vector3(0, 0, 0))
{
Vector3 n = legs[index].GetComponent<Leg>().getWorldPos();
n = Quaternion.Euler(0, step2[index], 0) * n;
@@ -116,5 +121,11 @@ public class Walk2 : MonoBehaviour
// rotate x,y around rotation.
legs[index].GetComponent<Leg>().setWorldPos(n);
}
else
{
// return to home
legs[index].GetComponent<Leg>().point += step4[index];
}
}
}
}