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: m_EditorClassIdentifier:
transformation: {x: 0, y: 2, z: 0} transformation: {x: 0, y: 2, z: 0}
transformation2: {x: 0, y: 0, 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: rotation2:
- {fileID: 636309705} - {fileID: 636309705}
- {fileID: 596626244} - {fileID: 596626244}
@@ -48756,7 +48756,7 @@ MonoBehaviour:
m_PrefabParentObject: {fileID: 0} m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 311513960} m_GameObject: {fileID: 311513960}
m_Enabled: 1 m_Enabled: 0
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62866dc69f17c5f40a7ec527e34e82f1, type: 3} m_Script: {fileID: 11500000, guid: 62866dc69f17c5f40a7ec527e34e82f1, type: 3}
m_Name: m_Name:
@@ -48769,7 +48769,7 @@ MonoBehaviour:
- {fileID: 1772413224} - {fileID: 1772413224}
- {fileID: 210611261} - {fileID: 210611261}
st: 5 st: 5
speed2: 30 speed2: 1
rotation: 0 rotation: 0
walkspeed: 1.5 walkspeed: 1.5
--- !u!114 &311513964 --- !u!114 &311513964
@@ -48791,7 +48791,7 @@ MonoBehaviour:
- {fileID: 1772413224} - {fileID: 1772413224}
- {fileID: 210611261} - {fileID: 210611261}
st: 5 st: 5
speed2: 20 speed2: 1
rotation: 5 rotation: 5
--- !u!1 &311874317 --- !u!1 &311874317
GameObject: GameObject:
+23 -33
View File
@@ -29,47 +29,37 @@ public class Serial {
public void send(int start, int a, int b, int c) public void send(int start, int a, int b, int c)
{ {
if (serialPort == null)
{
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
try
{
serialPort.Open();
serialPort.DiscardOutBuffer();
serialPort.DiscardInBuffer();
enabled = true;
}
catch
{
enabled = false;
}
}
if (enabled) if (enabled)
{ {
if (serialPort == null)
{
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
try
{
serialPort.Open();
serialPort.DiscardOutBuffer();
serialPort.DiscardInBuffer();
}
catch
{
enabled = false;
}
}
if (serialPort is SerialPort) if (serialPort is SerialPort)
{ {
string send = " #" + start.ToString() + " P" + a.ToString();
serialPort.Write(" #");
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(a.ToString());
start++; start++;
send = send + " #" + start.ToString() + " P" + b.ToString();
serialPort.Write(" #");
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(b.ToString());
start++; start++;
send = send + " #" + start.ToString() + " P" + c.ToString();
serialPort.Write(" #"); send = send + " \r";
serialPort.Write(start.ToString());
serialPort.Write(" P");
serialPort.Write(c.ToString());
serialPort.Write(" \r"); serialPort.Write(send);
} }
} }
} }
+2 -5
View File
@@ -92,11 +92,8 @@ public class Walk : MonoBehaviour
} }
else else
{ {
Vector3 t2 = s[t].pos; Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent<Leg>().point;
t2.x *= walkspeed; step2[index] = t2 / speed2;
// rotate x,y around rotation.
step2[index] = (Quaternion.Euler(0, rotation, 0) * t2) / speed2;
} }
} }
+18 -7
View File
@@ -15,6 +15,7 @@ public class Walk2 : MonoBehaviour
legsInitial.Add(legs[index].GetComponent<Leg>().point); legsInitial.Add(legs[index].GetComponent<Leg>().point);
step2.Add(0); step2.Add(0);
step3.Add(0); step3.Add(0);
step4.Add(new Vector3(0, 0, 0));
} }
} }
@@ -66,6 +67,7 @@ public class Walk2 : MonoBehaviour
//public float walkspeed = 1; //public float walkspeed = 1;
private List<float> step2 = new List<float>(); private List<float> step2 = new List<float>();
private List<float> step3 = new List<float>(); private List<float> step3 = new List<float>();
private List<Vector3> step4 = new List<Vector3>();
// Update is called once per frame // Update is called once per frame
void FixedUpdate() void FixedUpdate()
@@ -89,11 +91,12 @@ public class Walk2 : MonoBehaviour
{ {
step2[index] = (rotation * s[t].rotation) / speed2; step2[index] = (rotation * s[t].rotation) / speed2;
step3[index] = s[t].height / speed2; step3[index] = s[t].height / speed2;
step4[index] = new Vector3(0, 0, 0);
} }
else else
{ {
step2[index] = (rotation * s[t].rotation) / speed2; Vector3 t2 = legsInitial[index] - legs[index].GetComponent<Leg>().point;
step3[index] = s[t].height / speed2; step4[index] = t2 / speed2;
} }
} }
@@ -110,11 +113,19 @@ public class Walk2 : MonoBehaviour
{ {
for (int index = 0; index < legs.Count; ++index) for (int index = 0; index < legs.Count; ++index)
{ {
Vector3 n = legs[index].GetComponent<Leg>().getWorldPos(); if (step4[index] == new Vector3(0, 0, 0))
n = Quaternion.Euler(0, step2[index], 0) * n; {
n.y += step3[index]; Vector3 n = legs[index].GetComponent<Leg>().getWorldPos();
// rotate x,y around rotation. n = Quaternion.Euler(0, step2[index], 0) * n;
legs[index].GetComponent<Leg>().setWorldPos(n); n.y += step3[index];
// rotate x,y around rotation.
legs[index].GetComponent<Leg>().setWorldPos(n);
}
else
{
// return to home
legs[index].GetComponent<Leg>().point += step4[index];
}
} }
} }
} }