v6 rotational walking :D

This commit is contained in:
2018-11-14 22:22:38 +01:00
parent b505fe4618
commit 131529576c
9 changed files with 167 additions and 18 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+11 -1
View File
@@ -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;
+28 -12
View File
@@ -34428,7 +34428,6 @@ MonoBehaviour:
translateY: 0
translateZ: -5
pointShouldBe: {fileID: 32992308}
pos: {x: 0, y: 0, z: 0}
startServo: 22
--- !u!1 &211071650
GameObject:
@@ -48707,6 +48706,7 @@ GameObject:
- component: {fileID: 311513961}
- component: {fileID: 311513962}
- component: {fileID: 311513963}
- component: {fileID: 311513964}
m_Layer: 0
m_Name: RotationControl
m_TagString: Untagged
@@ -48738,7 +48738,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 30ea8dc0510444c42ae4b4db1f5ee2bd, type: 3}
m_Name:
m_EditorClassIdentifier:
transformation: {x: 0, y: 0, z: 0}
transformation: {x: 0, y: 2, z: 0}
transformation2: {x: 0, y: 0, z: 0}
rotation: {x: -1, y: 0, z: 2, w: 0}
rotation2:
@@ -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:
@@ -48772,6 +48772,27 @@ MonoBehaviour:
speed2: 5
rotation: 0
walkspeed: 1.5
--- !u!114 &311513964
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 311513960}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91e6f3895f276d94da1803128e6290e0, type: 3}
m_Name:
m_EditorClassIdentifier:
legs:
- {fileID: 636309705}
- {fileID: 596626244}
- {fileID: 1619174560}
- {fileID: 1453644144}
- {fileID: 1772413224}
- {fileID: 210611261}
st: 5
speed2: 5
rotation: 1
--- !u!1 &311874317
GameObject:
m_ObjectHideFlags: 0
@@ -92904,7 +92925,6 @@ MonoBehaviour:
translateY: 0
translateZ: 7
pointShouldBe: {fileID: 914986742}
pos: {x: 0, y: 0, z: 0}
startServo: 3
--- !u!1 &596816813
GameObject:
@@ -99428,7 +99448,6 @@ MonoBehaviour:
translateY: 0
translateZ: 5
pointShouldBe: {fileID: 2018746516}
pos: {x: 0, y: 0, z: 0}
startServo: 0
--- !u!1 &636734778
GameObject:
@@ -223943,8 +223962,8 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1389944203}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 10, y: 1, z: 10}
m_LocalPosition: {x: 0, y: -1, z: 0}
m_LocalScale: {x: 10, y: 2.5, z: 10}
m_Children: []
m_Father: {fileID: 1971572978}
m_RootOrder: 0
@@ -234755,7 +234774,6 @@ MonoBehaviour:
translateY: 0
translateZ: -5
pointShouldBe: {fileID: 591879371}
pos: {x: 0, y: 0, z: 0}
startServo: 16
--- !u!1 &1454125721
GameObject:
@@ -245844,8 +245862,8 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1525476315}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 5, y: 1, z: 13.5}
m_LocalPosition: {x: 0, y: -1, z: 0}
m_LocalScale: {x: 5, y: 2.5, z: 13.5}
m_Children: []
m_Father: {fileID: 1971572978}
m_RootOrder: 1
@@ -259278,7 +259296,6 @@ MonoBehaviour:
translateY: 0
translateZ: 5
pointShouldBe: {fileID: 1943602706}
pos: {x: 0, y: 0, z: 0}
startServo: 6
--- !u!1 &1619291355
GameObject:
@@ -283979,7 +283996,6 @@ MonoBehaviour:
translateY: 0
translateZ: -7
pointShouldBe: {fileID: 955360344}
pos: {x: 0, y: 0, z: 0}
startServo: 19
--- !u!1 &1772635191
GameObject:
+10 -3
View File
@@ -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)
+2 -2
View File
@@ -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;
+103
View File
@@ -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--;
}
}
+13
View File
@@ -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: