diff --git a/2018-unity-sim/Assets/Foot.cs b/2018-unity-sim/Assets/Foot.cs index ca37191..19607e5 100644 --- a/2018-unity-sim/Assets/Foot.cs +++ b/2018-unity-sim/Assets/Foot.cs @@ -131,7 +131,7 @@ public class Foot : Component RotateY(); RotateZ();*/ - // Z and X is working. Y has problems when combined with others. + // the order of these rotation transformations is important!!! Vector3 v = new Vector3((float)X, (float)Y, (float)Z); v = Quaternion.Euler((float)0, (float)rotationY, (float)0) * v; v = Quaternion.Euler((float)rotationX, (float)0, (float)0) * v; diff --git a/2018-unity-sim/Assets/Leg.cs b/2018-unity-sim/Assets/Leg.cs index 58393b3..d30967f 100644 --- a/2018-unity-sim/Assets/Leg.cs +++ b/2018-unity-sim/Assets/Leg.cs @@ -16,7 +16,7 @@ public class Leg : MonoBehaviour { public bool invert = false; - public double translateX = 5; + public double translateX = 0; public double translateY = 0; public double translateZ = 0; @@ -31,7 +31,7 @@ public class Leg : MonoBehaviour { } // Update is called once per frame - void Update() + public void FixedUpdate() { foot.X = point.x; foot.Y = point.y; diff --git a/2018-unity-sim/Assets/Main.unity b/2018-unity-sim/Assets/Main.unity index 98cf40c..981e277 100644 --- a/2018-unity-sim/Assets/Main.unity +++ b/2018-unity-sim/Assets/Main.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8a2be3952982ba00b2a7e7dbe0048ab7b2ee517dc1d3ec8c10a0011141abb118 -size 36028 +oid sha256:0b7396bf84046e0454ff9b50e8a912c5a16957bc69b409f12860d5f4f9254c73 +size 9964272 diff --git a/2018-unity-sim/Assets/RotationControl.cs b/2018-unity-sim/Assets/RotationControl.cs index 928f774..8797aa0 100644 --- a/2018-unity-sim/Assets/RotationControl.cs +++ b/2018-unity-sim/Assets/RotationControl.cs @@ -8,14 +8,16 @@ public class RotationControl : MonoBehaviour public List rotation2 = new List(); public GameObject body; - public double min = -15; - public double max = 15; + public float min = -15; + public float max = 15; public float speed = 0.3f; public float speed2 = 0.3f; public float speed3 = 0.3f; - bool dir = false; - bool dir2 = false; - bool dir3 = false; + public bool dir = false; + public bool dir2 = false; + public bool dir3 = false; + + public bool p = false, r = false, y = false; // Use this for initialization void Start () @@ -23,40 +25,68 @@ public class RotationControl : MonoBehaviour } // Update is called once per frame - void Update() + void FixedUpdate() { - if (!dir2 && rotation.x < max) - rotation.x += speed2; - else if (!dir2) - dir2 = !dir2; - else if (dir2 && rotation.x > min) - rotation.x -= speed2; - else if (dir2) - dir2 = !dir2; + if (p) + { + if (!dir2 && rotation.x < max) + rotation.x += speed2; + else if (!dir2) + { + dir2 = !dir2; + rotation.x = (float)max; + } + else if (dir2 && rotation.x > min) + rotation.x -= speed2; + else if (dir2) + { + dir2 = !dir2; + rotation.x = (float)min; + } + } - if (!dir3 && rotation.y < max) - rotation.y += speed3; - else if (!dir3) - dir3 = !dir3; - else if (dir3 && rotation.y > min) - rotation.y -= speed3; - else if (dir3) - dir3 = !dir3; + if (r) + { + if (!dir3 && rotation.y < max) + rotation.y += speed3; + else if (!dir3) + { + dir3 = !dir3; + rotation.y = (float)max; + } + else if (dir3 && rotation.y > min) + rotation.y -= speed3; + else if (dir3) + { + dir3 = !dir3; + rotation.y = (float)min; + } + } - if (!dir && rotation.z < max) - rotation.z += speed; - else if (!dir) - dir = !dir; - else if (dir && rotation.z > min) - rotation.z -= speed; - else if (dir) - dir = !dir; + if (y) + { + if (!dir && rotation.z < max) + rotation.z += speed; + else if (!dir) + { + dir = !dir; + rotation.z = (float)max; + } + else if (dir && rotation.z > min) + rotation.z -= speed; + else if (dir) + { + dir = !dir; + rotation.z = (float)min; + } + } body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1); for (int index = 0; index < rotation2.Count; ++index) { rotation2[index].GetComponent().rotation = rotation; + rotation2[index].GetComponent().FixedUpdate(); } } }