updated walk and controller input to joystick
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
-5
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Foot : Component
|
public class Foot : Component
|
||||||
@@ -19,7 +17,9 @@ public class Foot : Component
|
|||||||
// Inverse Kinemetics Region
|
// Inverse Kinemetics Region
|
||||||
double l3, s;
|
double l3, s;
|
||||||
|
|
||||||
double l1=10, l2=15;
|
public double l1=10; // top leg length
|
||||||
|
public double l2=15; // bottom leg length
|
||||||
|
static float knie_offset = 5.5f; // distancce from horziontal servo to knee servo.
|
||||||
|
|
||||||
public double X, Y, Z;
|
public double X, Y, Z;
|
||||||
public double rotationX=0, rotationY=0, rotationZ=0;
|
public double rotationX=0, rotationY=0, rotationZ=0;
|
||||||
@@ -28,8 +28,6 @@ public class Foot : Component
|
|||||||
public Vector3 transformation = new Vector3(0, 0, 0);
|
public Vector3 transformation = new Vector3(0, 0, 0);
|
||||||
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
static float knie_offset = 5.5f;
|
|
||||||
|
|
||||||
void RL3()
|
void RL3()
|
||||||
{
|
{
|
||||||
if ((X == 0) && (Z == 0))
|
if ((X == 0) && (Z == 0))
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5f676c461da1c254990d7719d77e6250
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1641405303
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Assets.JoyStick
|
||||||
|
{
|
||||||
|
class HandleHoystick : MonoBehaviour
|
||||||
|
{
|
||||||
|
public RotationControl bot;
|
||||||
|
public Walk walk;
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
float a2 = Remap(Input.GetAxis("1"), 1, -127, -1, 127);
|
||||||
|
float a1 = Remap(Input.GetAxis("2"), 1, -127, -1, 127);
|
||||||
|
float a3 = Remap(Input.GetAxis("3"), -1, -127, 1, 127);
|
||||||
|
|
||||||
|
float b2 = Remap(Input.GetAxis("4"), -1, -127, 1, 127);
|
||||||
|
float b3 = Remap(Input.GetAxis("5"), -1, -127, 1, 127);
|
||||||
|
float b1 = Remap(Input.GetAxis("6"), -1, -127, 1, 127);
|
||||||
|
|
||||||
|
//Debug.Log(Input.GetAxis("4"));
|
||||||
|
//Debug.Log(Remap(Input.GetAxis("4"), -1, -127, 1, 127));
|
||||||
|
|
||||||
|
bot.rotation = new Quaternion(limit(a2, -20, 20), -1 * limit(a3, -20, 20), -1 * limit(a1, -20, 20),
|
||||||
|
1);
|
||||||
|
|
||||||
|
float speed = (float)(Math.Sqrt(b1 * b1 + b2 * b2) / 127) * 3;
|
||||||
|
walk.walkspeed = speed < 0.5f ? 0 : speed;
|
||||||
|
|
||||||
|
float rotation = -1 * limit(b3 / 4, -5, 5);
|
||||||
|
walk.centerRotation = rotation < 0.5f && rotation > -0.5f ? 0 : rotation;
|
||||||
|
|
||||||
|
walk.walkDirection = (-1 * ConvertRadiansToDegrees((float)Math.Atan2(b2, b1)));
|
||||||
|
|
||||||
|
float rotationabs = Math.Abs(walk.centerRotation);
|
||||||
|
float speed2 = ((6 / 3) * walk.walkspeed) + ((6 / 5) * rotationabs);
|
||||||
|
speed2 = speed2 < 6 ? speed2 : 6;
|
||||||
|
walk.speed2 = (int)(10 - speed2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float limit(float input, float min, float max)
|
||||||
|
{
|
||||||
|
input = input / 6;
|
||||||
|
return (input < max & input > min) ? input : input < min ? min : max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float ConvertRadiansToDegrees(float radians)
|
||||||
|
{
|
||||||
|
float degrees = (float)((180 / Math.PI) * radians);
|
||||||
|
return (degrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Remap(float from, float fromMin, float toMin, float fromMax, float toMax)
|
||||||
|
{
|
||||||
|
var fromAbs = from - fromMin;
|
||||||
|
var fromMaxAbs = fromMax - fromMin;
|
||||||
|
|
||||||
|
var normal = fromAbs / fromMaxAbs;
|
||||||
|
|
||||||
|
var toMaxAbs = toMax - toMin;
|
||||||
|
var toAbs = toMaxAbs * normal;
|
||||||
|
|
||||||
|
var to = toAbs + toMin;
|
||||||
|
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: a4266f2a53eea3a43972b07e077212bc
|
guid: c5ce8a2605d301e44a4a210aa345ed62
|
||||||
timeCreated: 1542307321
|
timeCreated: 1641405303
|
||||||
licenseType: Free
|
licenseType: Free
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
+29
-19
@@ -1,12 +1,11 @@
|
|||||||
using System.Collections;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class Leg : MonoBehaviour {
|
public class Leg : MonoBehaviour {
|
||||||
public Transform Hip1;
|
public Transform Hip1;
|
||||||
public Transform Hip2;
|
public Transform Hip2;
|
||||||
public Transform Knie;
|
public Transform Knie;
|
||||||
|
|
||||||
|
// rotation angles for different servos
|
||||||
public double a1 = 0;
|
public double a1 = 0;
|
||||||
public double a2 = 0;
|
public double a2 = 0;
|
||||||
public double a3 = 0;
|
public double a3 = 0;
|
||||||
@@ -14,11 +13,12 @@ public class Leg : MonoBehaviour {
|
|||||||
public Vector3 point = new Vector3(10, 10, 0);
|
public Vector3 point = new Vector3(10, 10, 0);
|
||||||
public Quaternion rotation = new Quaternion(0, 0, 0, 0);
|
public Quaternion rotation = new Quaternion(0, 0, 0, 0);
|
||||||
|
|
||||||
public Vector3 transformation = new Vector3(0, 0, 0);
|
public Vector3 transformationBeforeRotation = new Vector3(0, 0, 0);
|
||||||
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
public Vector3 transformationAfterRotation = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
public bool invert = false;
|
public bool invertForLeftLeg = false;
|
||||||
|
|
||||||
|
// translation to change origin to middle of body
|
||||||
public double translateX = 0;
|
public double translateX = 0;
|
||||||
public double translateY = 0;
|
public double translateY = 0;
|
||||||
public double translateZ = 0;
|
public double translateZ = 0;
|
||||||
@@ -51,16 +51,16 @@ public class Leg : MonoBehaviour {
|
|||||||
foot.translateZ = translateZ;
|
foot.translateZ = translateZ;
|
||||||
|
|
||||||
// transform before rotation.
|
// transform before rotation.
|
||||||
foot.transformation = transformation;
|
foot.transformation = transformationBeforeRotation;
|
||||||
|
|
||||||
// transform after rotation.
|
// transform after rotation.
|
||||||
foot.transformation2 = transformation2;
|
foot.transformation2 = transformationAfterRotation;
|
||||||
|
|
||||||
foot.invert = invert;
|
foot.invert = invertForLeftLeg;
|
||||||
|
|
||||||
foot.setleg();
|
foot.setleg();
|
||||||
|
|
||||||
if (!invert)
|
if (!invertForLeftLeg)
|
||||||
{
|
{
|
||||||
a1 = foot.O1 - 90;
|
a1 = foot.O1 - 90;
|
||||||
a2 = 90 - foot.O2;
|
a2 = 90 - foot.O2;
|
||||||
@@ -73,23 +73,33 @@ public class Leg : MonoBehaviour {
|
|||||||
a3 = foot.O3 - 90;
|
a3 = foot.O3 - 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!invert && startServo != -1)
|
if (!invertForLeftLeg && startServo != -1)
|
||||||
{
|
{
|
||||||
|
// Serial.Instance.send(startServo,
|
||||||
|
// (int)Remap((float)a1, -90, 90, 2500, 500),
|
||||||
|
// (int)Remap((float)a2, -90, 90, 2500, 500), // 0 is middel
|
||||||
|
// (int)Remap((float)a3, 90, -90, 2500, 500)); // 0 is middel
|
||||||
|
if(false)
|
||||||
Serial.Instance.send(startServo,
|
Serial.Instance.send(startServo,
|
||||||
(int)Remap((float)a1, -90, 90, 2500, 500),
|
(int)Remap((float)a1, -90, 90, 0, 180),
|
||||||
(int)Remap((float)a2, -90, 90, 2500, 500), // 0 is middel
|
(int)Remap((float)a2, 90, -90, 0, 180), // 0 is middel
|
||||||
(int)Remap((float)a3, 90, -90, 2500, 500)); // 0 is middel
|
(int)Remap((float)a3, -90, 90, 0, 180)); // 0 is middel
|
||||||
}
|
}
|
||||||
else if (invert && startServo != -1)
|
else if (invertForLeftLeg && startServo != -1)
|
||||||
{
|
{
|
||||||
double a1 = foot.O1 - 90;
|
double a1 = foot.O1 - 90;
|
||||||
double a2 = 90 - foot.O2;
|
double a2 = 90 - foot.O2;
|
||||||
double a3 = foot.O3 - 90;
|
double a3 = foot.O3 - 90;
|
||||||
|
|
||||||
Serial.Instance.send(startServo,
|
// Serial.Instance.send(startServo,
|
||||||
(int)Remap((float)a1, -90, 90, 500, 2500),
|
// (int)Remap((float)a1, -90, 90, 500, 2500),
|
||||||
(int)Remap((float)a2, -90, 90, 500, 2500), // 0 is middel
|
// (int)Remap((float)a2, -90, 90, 500, 2500), // 0 is middel
|
||||||
(int)Remap((float)a3, 90, -90, 500, 2500)); // 0 is middel
|
// (int)Remap((float)a3, 90, -90, 500, 2500)); // 0 is middel
|
||||||
|
if (false)
|
||||||
|
Serial.Instance.send(startServo,
|
||||||
|
(int)Remap((float)a1, 90, -90, 0, 180),
|
||||||
|
(int)Remap((float)a2, -90, 90, 0, 180), // 0 is middel
|
||||||
|
(int)Remap((float)a3, 90, -90, 0, 180)); // 0 is middel
|
||||||
}
|
}
|
||||||
|
|
||||||
Hip1.transform.localRotation = Quaternion.Euler(0, (float)a1, 0);
|
Hip1.transform.localRotation = Quaternion.Euler(0, (float)a1, 0);
|
||||||
|
|||||||
+75
-77
@@ -10529,7 +10529,7 @@ GameObject:
|
|||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 0
|
||||||
--- !u!4 &73925799
|
--- !u!4 &73925799
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -10541,7 +10541,7 @@ Transform:
|
|||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 5
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &73925800
|
--- !u!114 &73925800
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -10549,7 +10549,7 @@ MonoBehaviour:
|
|||||||
m_PrefabParentObject: {fileID: 0}
|
m_PrefabParentObject: {fileID: 0}
|
||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 73925798}
|
m_GameObject: {fileID: 73925798}
|
||||||
m_Enabled: 1
|
m_Enabled: 0
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 7fa025fa8dcb3a249b67fc0e2fe67b44, type: 3}
|
m_Script: {fileID: 11500000, guid: 7fa025fa8dcb3a249b67fc0e2fe67b44, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
@@ -10563,6 +10563,7 @@ MonoBehaviour:
|
|||||||
b2: 0
|
b2: 0
|
||||||
b3: 0
|
b3: 0
|
||||||
enabled: 0
|
enabled: 0
|
||||||
|
enabled_send: 0
|
||||||
--- !u!1 &74230589
|
--- !u!1 &74230589
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -14153,7 +14154,7 @@ Transform:
|
|||||||
- {fileID: 379804153}
|
- {fileID: 379804153}
|
||||||
- {fileID: 1946365704}
|
- {fileID: 1946365704}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 5
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &95074500
|
--- !u!1 &95074500
|
||||||
GameObject:
|
GameObject:
|
||||||
@@ -34470,14 +34471,14 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: 5, y: -15, z: -13}
|
point: {x: 5, y: -15, z: -13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 1
|
invertForLeftLeg: 1
|
||||||
translateX: 5
|
translateX: 5
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: -5
|
translateZ: -5
|
||||||
pointShouldBe: {fileID: 32992308}
|
pointShouldBe: {fileID: 32992308}
|
||||||
startServo: 22
|
startServo: 9
|
||||||
--- !u!1 &211071650
|
--- !u!1 &211071650
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -48754,8 +48755,6 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 311513961}
|
- component: {fileID: 311513961}
|
||||||
- component: {fileID: 311513962}
|
- component: {fileID: 311513962}
|
||||||
- component: {fileID: 311513963}
|
|
||||||
- component: {fileID: 311513964}
|
|
||||||
- component: {fileID: 311513965}
|
- component: {fileID: 311513965}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: RotationControl
|
m_Name: RotationControl
|
||||||
@@ -48771,7 +48770,7 @@ Transform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 311513960}
|
m_GameObject: {fileID: 311513960}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 27.58, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
@@ -48800,49 +48799,6 @@ MonoBehaviour:
|
|||||||
- {fileID: 210611261}
|
- {fileID: 210611261}
|
||||||
body: {fileID: 2129559090}
|
body: {fileID: 2129559090}
|
||||||
body2: {fileID: 1971572977}
|
body2: {fileID: 1971572977}
|
||||||
--- !u!114 &311513963
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_PrefabParentObject: {fileID: 0}
|
|
||||||
m_PrefabInternal: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 311513960}
|
|
||||||
m_Enabled: 0
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 62866dc69f17c5f40a7ec527e34e82f1, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
legs:
|
|
||||||
- {fileID: 636309705}
|
|
||||||
- {fileID: 596626244}
|
|
||||||
- {fileID: 1619174560}
|
|
||||||
- {fileID: 1453644144}
|
|
||||||
- {fileID: 1772413224}
|
|
||||||
- {fileID: 210611261}
|
|
||||||
st: 5
|
|
||||||
speed2: 1
|
|
||||||
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: 0
|
|
||||||
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: 1
|
|
||||||
rotation: 5
|
|
||||||
--- !u!114 &311513965
|
--- !u!114 &311513965
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -48865,7 +48821,7 @@ MonoBehaviour:
|
|||||||
speed2: 10
|
speed2: 10
|
||||||
walkDirection: 0
|
walkDirection: 0
|
||||||
centerRotation: 0
|
centerRotation: 0
|
||||||
walkspeed: 3
|
walkspeed: 0
|
||||||
--- !u!1 &311874317
|
--- !u!1 &311874317
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -92991,9 +92947,9 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: 0, y: -15, z: 13}
|
point: {x: 0, y: -15, z: 13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 0
|
invertForLeftLeg: 0
|
||||||
translateX: 0
|
translateX: 0
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: 6.5
|
translateZ: 6.5
|
||||||
@@ -99514,14 +99470,14 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: -5, y: -15, z: 13}
|
point: {x: -5, y: -15, z: 13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 0
|
invertForLeftLeg: 0
|
||||||
translateX: -5
|
translateX: -5
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: 5
|
translateZ: 5
|
||||||
pointShouldBe: {fileID: 2018746516}
|
pointShouldBe: {fileID: 2018746516}
|
||||||
startServo: 0
|
startServo: 6
|
||||||
--- !u!1 &636734778
|
--- !u!1 &636734778
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -228420,7 +228376,7 @@ Transform:
|
|||||||
m_LocalScale: {x: 100, y: 1, z: 100}
|
m_LocalScale: {x: 100, y: 1, z: 100}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 4
|
m_RootOrder: 6
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &1414444048
|
--- !u!1 &1414444048
|
||||||
GameObject:
|
GameObject:
|
||||||
@@ -234926,14 +234882,14 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: -5, y: -15, z: -13}
|
point: {x: -5, y: -15, z: -13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 1
|
invertForLeftLeg: 1
|
||||||
translateX: -5
|
translateX: -5
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: -5
|
translateZ: -5
|
||||||
pointShouldBe: {fileID: 591879371}
|
pointShouldBe: {fileID: 591879371}
|
||||||
startServo: 16
|
startServo: 15
|
||||||
--- !u!1 &1454125721
|
--- !u!1 &1454125721
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -259448,14 +259404,14 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: 5, y: -15, z: 13}
|
point: {x: 5, y: -15, z: 13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 0
|
invertForLeftLeg: 0
|
||||||
translateX: 5
|
translateX: 5
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: 5
|
translateZ: 5
|
||||||
pointShouldBe: {fileID: 1943602706}
|
pointShouldBe: {fileID: 1943602706}
|
||||||
startServo: 6
|
startServo: 0
|
||||||
--- !u!1 &1619291355
|
--- !u!1 &1619291355
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -265153,6 +265109,48 @@ Transform:
|
|||||||
m_Father: {fileID: 1921902568}
|
m_Father: {fileID: 1921902568}
|
||||||
m_RootOrder: 2
|
m_RootOrder: 2
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &1645933597
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
serializedVersion: 5
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1645933599}
|
||||||
|
- component: {fileID: 1645933598}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Input
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &1645933598
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1645933597}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c5ce8a2605d301e44a4a210aa345ed62, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
bot: {fileID: 311513962}
|
||||||
|
walk: {fileID: 311513965}
|
||||||
|
--- !u!4 &1645933599
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1645933597}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -36.648933, y: -31.721676, z: -22.529099}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 2
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &1646259228
|
--- !u!1 &1646259228
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -284148,14 +284146,14 @@ MonoBehaviour:
|
|||||||
a3: 0
|
a3: 0
|
||||||
point: {x: 0, y: -15, z: -13}
|
point: {x: 0, y: -15, z: -13}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
transformation: {x: 0, y: 0, z: 0}
|
transformationBeforeRotation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformationAfterRotation: {x: 0, y: 0, z: 0}
|
||||||
invert: 1
|
invertForLeftLeg: 1
|
||||||
translateX: 0
|
translateX: 0
|
||||||
translateY: 0
|
translateY: 0
|
||||||
translateZ: -6.5
|
translateZ: -6.5
|
||||||
pointShouldBe: {fileID: 955360344}
|
pointShouldBe: {fileID: 955360344}
|
||||||
startServo: 19
|
startServo: 12
|
||||||
--- !u!1 &1772635191
|
--- !u!1 &1772635191
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -299532,7 +299530,7 @@ Transform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1867357888}
|
m_GameObject: {fileID: 1867357888}
|
||||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
m_LocalPosition: {x: 45.12, y: 56.06, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
@@ -339239,7 +339237,7 @@ Transform:
|
|||||||
- {fileID: 1640079164}
|
- {fileID: 1640079164}
|
||||||
- {fileID: 1971572978}
|
- {fileID: 1971572978}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 2
|
m_RootOrder: 4
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &2130020849
|
--- !u!1 &2130020849
|
||||||
GameObject:
|
GameObject:
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ public class RotationControl : MonoBehaviour
|
|||||||
//rotation.y = r2.update();
|
//rotation.y = r2.update();
|
||||||
//rotation.z = r3.update();
|
//rotation.z = r3.update();
|
||||||
|
|
||||||
//transformation.x = r4.update();
|
//transformationBeforeRotation.x = r4.update();
|
||||||
//transformation.y = r5.update();
|
//transformationBeforeRotation.y = r5.update();
|
||||||
//transformation.z = r6.update();
|
//transformationBeforeRotation.z = r6.update();
|
||||||
|
|
||||||
/*transformation2.x = r7.update();
|
/*transformationAfterRotation.x = r7.update();
|
||||||
transformation2.y = r8.update();
|
transformationAfterRotation.y = r8.update();
|
||||||
transformation2.z = r9.update();*/
|
transformationAfterRotation.z = r9.update();*/
|
||||||
|
|
||||||
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
|
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
|
||||||
body.transform.position = transformation;
|
body.transform.position = transformation;
|
||||||
@@ -96,8 +96,8 @@ public class RotationControl : MonoBehaviour
|
|||||||
for (int index = 0; index < rotation2.Count; ++index)
|
for (int index = 0; index < rotation2.Count; ++index)
|
||||||
{
|
{
|
||||||
rotation2[index].GetComponent<Leg>().rotation = rotation;
|
rotation2[index].GetComponent<Leg>().rotation = rotation;
|
||||||
rotation2[index].GetComponent<Leg>().transformation = transformation;
|
rotation2[index].GetComponent<Leg>().transformationBeforeRotation = transformation;
|
||||||
rotation2[index].GetComponent<Leg>().transformation2 = transformation2;
|
rotation2[index].GetComponent<Leg>().transformationAfterRotation = transformation2;
|
||||||
rotation2[index].GetComponent<Leg>().FixedUpdate();
|
rotation2[index].GetComponent<Leg>().FixedUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using System.Collections;
|
|
||||||
using System.IO.Ports;
|
|
||||||
|
|
||||||
public class Serial {
|
|
||||||
private static Serial instance;
|
|
||||||
|
|
||||||
private Serial() { }
|
|
||||||
|
|
||||||
~Serial() {
|
|
||||||
serialPort.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Serial Instance
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (instance == null)
|
|
||||||
{
|
|
||||||
instance = new Serial();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool enabled = false;
|
|
||||||
|
|
||||||
SerialPort serialPort;
|
|
||||||
|
|
||||||
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 (serialPort is SerialPort)
|
|
||||||
{
|
|
||||||
string send = " #" + start.ToString() + " P" + a.ToString();
|
|
||||||
start++;
|
|
||||||
send = send + " #" + start.ToString() + " P" + b.ToString();
|
|
||||||
start++;
|
|
||||||
send = send + " #" + start.ToString() + " P" + c.ToString();
|
|
||||||
|
|
||||||
send = send + " \r";
|
|
||||||
|
|
||||||
serialPort.Write(send);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 942facdab943ceb4ca29453f4ee4d1b3
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1641404792
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO.Ports;
|
||||||
|
using Random = System.Random;
|
||||||
|
|
||||||
|
public class Serial
|
||||||
|
{
|
||||||
|
private static Serial instance;
|
||||||
|
private int rnd = 0;
|
||||||
|
|
||||||
|
private Serial()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~Serial()
|
||||||
|
{
|
||||||
|
serialPort.Close();
|
||||||
|
serialPort.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Serial Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new Serial();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool enabled = false;
|
||||||
|
|
||||||
|
public SerialPort serialPort;
|
||||||
|
|
||||||
|
public int[] values = new int[18];
|
||||||
|
|
||||||
|
public static string ByteArrayToString(byte[] ba)
|
||||||
|
{
|
||||||
|
return BitConverter.ToString(ba).Replace("-", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(int start, int a, int b, int c)
|
||||||
|
{
|
||||||
|
if (serialPort == null)
|
||||||
|
{
|
||||||
|
serialPort = new SerialPort(@"\\.\" + "COM4", 250000);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serialPort.Parity = Parity.Even;
|
||||||
|
serialPort.StopBits = StopBits.One;
|
||||||
|
serialPort.DataBits = 8;
|
||||||
|
serialPort.Open();
|
||||||
|
serialPort.DiscardOutBuffer();
|
||||||
|
serialPort.DiscardInBuffer();
|
||||||
|
System.Threading.Thread.Sleep(1000);
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
values[start] = a;
|
||||||
|
values[++start] = b;
|
||||||
|
values[++start] = c;
|
||||||
|
|
||||||
|
if (serialPort is SerialPort && start == 17)
|
||||||
|
{
|
||||||
|
// string send = "s";
|
||||||
|
byte[] send = new byte[18+1+2];
|
||||||
|
send[18] = 0x00;
|
||||||
|
send[19] = 0xfe;
|
||||||
|
send[20] = 0xff;
|
||||||
|
// send[21] = 0xff;
|
||||||
|
|
||||||
|
// if (rnd == 0)
|
||||||
|
// {
|
||||||
|
//rnd = 1;
|
||||||
|
for (int i = 0; i < 18; i++)
|
||||||
|
{
|
||||||
|
//string crc = ((i) * (values[i])) + "";
|
||||||
|
//send = send + (i).ToString() + "_" + (values[i]).ToString() + "," + crc + "=";
|
||||||
|
byte[] intBytes = BitConverter.GetBytes(values[i]);
|
||||||
|
if (BitConverter.IsLittleEndian)
|
||||||
|
Array.Reverse(intBytes);
|
||||||
|
send[i] = intBytes[3];
|
||||||
|
send[18] += send[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug.Log(ByteArrayToString(send));
|
||||||
|
serialPort.Write(send, 0, 18+1+2);
|
||||||
|
serialPort.BaseStream.Flush();
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// rnd = 0;
|
||||||
|
// for (int i = 10; i < 18; i++)
|
||||||
|
// {
|
||||||
|
// string crc = ((i + 3) * (values[i])) + "";
|
||||||
|
//
|
||||||
|
// send = send + (i + 2).ToString() + "_" + (values[i]).ToString() + "," + crc + "=";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Debug.Log(send);
|
||||||
|
// serialPort.Write(send);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
/*using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
@@ -67,3 +67,4 @@ public class Serial2 : MonoBehaviour{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
//using System;
|
||||||
|
//using UnityEngine;
|
||||||
|
//using System.Collections;
|
||||||
|
//using System.IO.Ports;
|
||||||
|
//using System.Linq;
|
||||||
|
//using UnityEngine.UI;
|
||||||
|
|
||||||
|
//public class Serial3 : MonoBehaviour{
|
||||||
|
|
||||||
|
// public RotationControl bot;
|
||||||
|
// public Walk walk;
|
||||||
|
|
||||||
|
// public float a1, a2, a3, b1, b2, b3;
|
||||||
|
|
||||||
|
// // ~Serial3()
|
||||||
|
// // {
|
||||||
|
// // serialPort.Close();
|
||||||
|
// // serialPort.Dispose();
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// public bool enabled = false;
|
||||||
|
// public bool enabled_send = false;
|
||||||
|
|
||||||
|
// SerialPort serialPort;
|
||||||
|
|
||||||
|
// public void Update()
|
||||||
|
// {
|
||||||
|
// if (serialPort == null)
|
||||||
|
// {
|
||||||
|
// serialPort = new SerialPort(@"\\.\" + "COM7", 230400);
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// serialPort.NewLine = "\r\n";
|
||||||
|
|
||||||
|
//// serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
|
||||||
|
|
||||||
|
// serialPort.Open();
|
||||||
|
// serialPort.DiscardOutBuffer();
|
||||||
|
// serialPort.DiscardInBuffer();
|
||||||
|
|
||||||
|
// enabled = true;
|
||||||
|
// }
|
||||||
|
// catch
|
||||||
|
// {
|
||||||
|
// enabled = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (enabled)
|
||||||
|
// {
|
||||||
|
// serialPort = Serial.Instance.serialPort;
|
||||||
|
// Serial.Instance.enabled = enabled_send;
|
||||||
|
// if (serialPort is SerialPort)
|
||||||
|
// {
|
||||||
|
// string received = serialPort.ReadLine();
|
||||||
|
// string[] data = received.Split(',');
|
||||||
|
|
||||||
|
// foreach (string d in data)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// string[] ch = d.Split('_');
|
||||||
|
|
||||||
|
// int channel = int.Parse(ch.First());
|
||||||
|
// float value = float.Parse(ch.Last());
|
||||||
|
|
||||||
|
// switch (channel)
|
||||||
|
// {
|
||||||
|
// case 0:
|
||||||
|
// a1 = value - 127;
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// a2 = value - 127;
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// a3 = value - 127;
|
||||||
|
// break;
|
||||||
|
// case 3:
|
||||||
|
// b1 = value - 127;
|
||||||
|
// break;
|
||||||
|
// case 4:
|
||||||
|
// b2 = value - 127;
|
||||||
|
// break;
|
||||||
|
// case 5:
|
||||||
|
// b3 = value - 127;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// bot.rotation = new Quaternion(limit(a2, -20, 20), -1 * limit(a3, -20, 20), -1 * limit(a1, -20, 20),
|
||||||
|
// 1);
|
||||||
|
|
||||||
|
// float speed = (float) (Math.Sqrt(b1 * b1 + b2 * b2) / 127) * 3;
|
||||||
|
// walk.walkspeed = speed < 0.5f ? 0 : speed;
|
||||||
|
|
||||||
|
// float rotation = -1 * limit(b3/4, -5, 5);
|
||||||
|
// walk.centerRotation = rotation < 0.5f && rotation > -0.5f ? 0 : rotation;
|
||||||
|
|
||||||
|
// walk.walkDirection = (-1 * ConvertRadiansToDegrees((float) Math.Atan2(b2, b1)));
|
||||||
|
|
||||||
|
// float rotationabs = Math.Abs(walk.centerRotation);
|
||||||
|
// float speed2 = ((6 / 3) * walk.walkspeed) + ((6/5) * rotationabs);
|
||||||
|
// speed2 = speed2 < 6 ? speed2 : 6;
|
||||||
|
// walk.speed2 = (int)(10 - speed2);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
|
||||||
|
// {
|
||||||
|
// SerialPort serialPort = (SerialPort)sender;
|
||||||
|
|
||||||
|
// if (enabled)
|
||||||
|
// {
|
||||||
|
// if (serialPort is SerialPort)
|
||||||
|
// {
|
||||||
|
// string received = serialPort.ReadLine();
|
||||||
|
// string[] data = received.Split(',');
|
||||||
|
|
||||||
|
// foreach (string d in data)
|
||||||
|
// {
|
||||||
|
// // if (data == "\r")
|
||||||
|
// // continue;
|
||||||
|
|
||||||
|
// string[] ch = d.Split('_');
|
||||||
|
|
||||||
|
// int channel = int.Parse(ch.First());
|
||||||
|
// float value = float.Parse(ch.Last());
|
||||||
|
|
||||||
|
// switch (channel)
|
||||||
|
// {
|
||||||
|
// case 0:
|
||||||
|
// a1 = value;
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// a2 = value;
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// a3 = value;
|
||||||
|
// break;
|
||||||
|
// case 3:
|
||||||
|
// b1 = value;
|
||||||
|
// break;
|
||||||
|
// case 4:
|
||||||
|
// b2 = value;
|
||||||
|
// break;
|
||||||
|
// case 5:
|
||||||
|
// b3 = value;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // bot.rotation = new Quaternion(-1* limit(y, -30, 30), 0, -1* limit(x, -30, 30), 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public float limit(float input, float min, float max)
|
||||||
|
// {
|
||||||
|
// input = input / 6;
|
||||||
|
// return (input < max & input > min) ? input : input < min ? min : max;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public float ConvertRadiansToDegrees(float radians)
|
||||||
|
// {
|
||||||
|
// float degrees = (float)((180 / Math.PI) * radians);
|
||||||
|
// return (degrees);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
using System.Collections;
|
|
||||||
using System.IO.Ports;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class Serial3 : MonoBehaviour{
|
|
||||||
|
|
||||||
public RotationControl bot;
|
|
||||||
public Walk3 walk;
|
|
||||||
|
|
||||||
public float a1, a2, a3, b1, b2, b3;
|
|
||||||
|
|
||||||
~Serial3() {
|
|
||||||
serialPort.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool enabled = false;
|
|
||||||
|
|
||||||
SerialPort serialPort;
|
|
||||||
|
|
||||||
public void Update()
|
|
||||||
{
|
|
||||||
if (serialPort == null)
|
|
||||||
{
|
|
||||||
serialPort = new SerialPort(@"\\.\" + "COM7", 115200);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
serialPort.NewLine = "\r\n";
|
|
||||||
|
|
||||||
// serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
|
|
||||||
|
|
||||||
serialPort.Open();
|
|
||||||
serialPort.DiscardOutBuffer();
|
|
||||||
serialPort.DiscardInBuffer();
|
|
||||||
|
|
||||||
enabled = true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enabled)
|
|
||||||
{
|
|
||||||
if (serialPort is SerialPort)
|
|
||||||
{
|
|
||||||
string received = serialPort.ReadLine();
|
|
||||||
string[] data = received.Split(',');
|
|
||||||
|
|
||||||
foreach (string d in data)
|
|
||||||
{
|
|
||||||
|
|
||||||
string[] ch = d.Split('_');
|
|
||||||
|
|
||||||
int channel = int.Parse(ch.First());
|
|
||||||
float value = float.Parse(ch.Last());
|
|
||||||
|
|
||||||
switch (channel)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
a1 = value - 127;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
a2 = value - 127;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
a3 = value - 127;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
b1 = value - 127;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
b2 = value - 127;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
b3 = value - 127;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.rotation = new Quaternion(limit(a2, -20, 20), -1 * limit(a3, -20, 20), -1 * limit(a1, -20, 20),
|
|
||||||
1);
|
|
||||||
|
|
||||||
float speed = (float) (Math.Sqrt(b1 * b1 + b2 * b2) / 127) * 3;
|
|
||||||
walk.walkspeed = speed < 0.5f ? 0 : speed;
|
|
||||||
|
|
||||||
float rotation = -1 * limit(b3/4, -5, 5);
|
|
||||||
walk.centerRotation = rotation < 0.5f && rotation > -0.5f ? 0 : rotation;
|
|
||||||
|
|
||||||
walk.walkDirection = (-1 * ConvertRadiansToDegrees((float) Math.Atan2(b2, b1)));
|
|
||||||
|
|
||||||
float rotationabs = Math.Abs(walk.centerRotation);
|
|
||||||
float speed2 = ((6 / 3) * walk.walkspeed) + ((6/5) * rotationabs);
|
|
||||||
speed2 = speed2 < 6 ? speed2 : 6;
|
|
||||||
walk.speed2 = (int)(10 - speed2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
|
|
||||||
{
|
|
||||||
SerialPort serialPort = (SerialPort)sender;
|
|
||||||
|
|
||||||
if (enabled)
|
|
||||||
{
|
|
||||||
if (serialPort is SerialPort)
|
|
||||||
{
|
|
||||||
string received = serialPort.ReadLine();
|
|
||||||
string[] data = received.Split(',');
|
|
||||||
|
|
||||||
foreach (string d in data)
|
|
||||||
{
|
|
||||||
// if (data == "\r")
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
string[] ch = d.Split('_');
|
|
||||||
|
|
||||||
int channel = int.Parse(ch.First());
|
|
||||||
float value = float.Parse(ch.Last());
|
|
||||||
|
|
||||||
switch (channel)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
a1 = value;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
a2 = value;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
a3 = value;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
b1 = value;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
b2 = value;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
b3 = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// bot.rotation = new Quaternion(-1* limit(y, -30, 30), 0, -1* limit(x, -30, 30), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float limit(float input, float min, float max)
|
|
||||||
{
|
|
||||||
input = input / 6;
|
|
||||||
return (input < max & input > min) ? input : input < min ? min : max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float ConvertRadiansToDegrees(float radians)
|
|
||||||
{
|
|
||||||
float degrees = (float)((180 / Math.PI) * radians);
|
|
||||||
return (degrees);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+144
-26
@@ -13,19 +13,32 @@ public class Walk : MonoBehaviour
|
|||||||
for (int index = 0; index < legs.Count; ++index)
|
for (int index = 0; index < legs.Count; ++index)
|
||||||
{
|
{
|
||||||
legsInitial.Add(legs[index].GetComponent<Leg>().point);
|
legsInitial.Add(legs[index].GetComponent<Leg>().point);
|
||||||
step2.Add( new Vector3() );
|
step2.Add(0);
|
||||||
|
step6.Add(false);
|
||||||
|
//step3.Add(0);
|
||||||
|
//step4.Add(new Vector3(0, 0, 0));
|
||||||
|
step5.Add(new Vector3());
|
||||||
|
|
||||||
|
freeze.Add(false);
|
||||||
|
freeze_y.Add(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct step
|
struct step
|
||||||
{
|
{
|
||||||
public Vector3 pos;
|
public Vector3 pos;
|
||||||
|
public float rotation;
|
||||||
|
public float height;
|
||||||
public bool inAir;
|
public bool inAir;
|
||||||
|
public bool inRest;
|
||||||
|
|
||||||
public step(Vector3 p, bool i)
|
public step(Vector3 p, float r, float h, bool i, bool ir)
|
||||||
{
|
{
|
||||||
pos = p;
|
pos = p;
|
||||||
|
rotation = r;
|
||||||
|
height = 0;
|
||||||
inAir = i;
|
inAir = i;
|
||||||
|
inRest = ir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,63 +50,159 @@ public class Walk : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
step[] s = {
|
step[] s = {
|
||||||
new step(new Vector3(-1, 0, 0), false),
|
new step(new Vector3(-1, 0, 0), -1, 0, false, false),
|
||||||
|
|
||||||
new step(new Vector3(0, -2, 0), false),
|
new step(new Vector3(0, -2, 0), 0, 0, false, false),
|
||||||
|
|
||||||
new step(new Vector3(0, 0, 0), false), // rest
|
new step(new Vector3(0, 0, 0), 0, 0, false, false), // rest
|
||||||
|
|
||||||
new step(new Vector3(1, 0, 0), false),
|
new step(new Vector3(1, 0, 0), 1, 0, false, true), // down middle
|
||||||
new step(new Vector3(1, 0, 0), false),
|
new step(new Vector3(1, 0, 0), 1, 0, false, false),
|
||||||
|
|
||||||
new step(new Vector3(0, 0, 0), false), // rest
|
new step(new Vector3(0, 0, 0), 0, 0, false, false), // rest
|
||||||
|
|
||||||
new step(new Vector3(0, 2, 0), false),
|
new step(new Vector3(0, 2, 0), 0, 0, false, false),
|
||||||
new step(new Vector3(-1, 0, 0), true),
|
new step(new Vector3(-1, 0, 0), -1, 0, true, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
public int st = 5;
|
public int st = 5;
|
||||||
public int speed2 = 30;
|
public int speed2 = 30;
|
||||||
int speed = 10;
|
int speed = 10;
|
||||||
|
|
||||||
public float rotation = 0;
|
public float walkDirection = 0;
|
||||||
|
public float centerRotation = 0;
|
||||||
|
|
||||||
int size = 8;
|
int size = 8;
|
||||||
|
|
||||||
public float walkspeed = 1;
|
public float walkspeed = 1;
|
||||||
|
|
||||||
private List<Vector3> step2 = new List<Vector3>();
|
private List<float> step2 = new List<float>();
|
||||||
|
//private List<float> step3 = new List<float>();
|
||||||
|
//private List<Vector3> step4 = new List<Vector3>();
|
||||||
|
private List<Vector3> step5 = new List<Vector3>();
|
||||||
|
private List<bool> step6 = new List<bool>();
|
||||||
|
|
||||||
|
private List<bool> freeze = new List<bool>();
|
||||||
|
private List<bool> freeze_y = new List<bool>();
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (speed <= 0)
|
if (speed <= 0)
|
||||||
{
|
{
|
||||||
if (st >= size-1)
|
if (st >= size - 1)
|
||||||
st = 0;
|
st = 0;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
st++;
|
st++;
|
||||||
|
|
||||||
|
if (centerRotation == 0 && walkspeed == 0)
|
||||||
|
{
|
||||||
|
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].inRest)
|
||||||
|
{
|
||||||
|
Vector3 lp = legs[index].GetComponent<Leg>().getLocalPos(); // + s[t].pos;
|
||||||
|
//lp.y -= 2;
|
||||||
|
if ((Mathf.Abs(lp.y - (legsInitial[index].y - 2)) < 0.0001f)
|
||||||
|
&& (Mathf.Abs(lp.z - legsInitial[index].z) < 0.0001f)
|
||||||
|
&& (Mathf.Abs(lp.x - legsInitial[index].x) < 1.0001f))
|
||||||
|
{
|
||||||
|
freeze[index] = true;
|
||||||
|
freeze_y[index] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*else
|
||||||
|
{
|
||||||
|
freeze[index] = false;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int index = 0; index < legs.Count; index++)
|
||||||
|
{
|
||||||
|
freeze[index] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int index = 0; index < legs.Count; ++index)
|
for (int index = 0; index < legs.Count; ++index)
|
||||||
{
|
{
|
||||||
int t = st;
|
int t = st;
|
||||||
if (index == 1 || index == 3 || index == 5)
|
|
||||||
{
|
|
||||||
t = offset(st, 4, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s[t].inAir == false)
|
if (true)
|
||||||
{
|
{
|
||||||
Vector3 t2 = s[t].pos;
|
// Hex walk
|
||||||
t2.x *= walkspeed;
|
if (index == 1 || index == 3 || index == 5)
|
||||||
|
{
|
||||||
// rotate x,y around rotation.
|
t = offset(st, 4, size);
|
||||||
step2[index] = (Quaternion.Euler(0, rotation, 0) * t2) / speed2;
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent<Leg>().point;
|
// One leg at a time walk
|
||||||
step2[index] = t2 / speed2;
|
switch (index)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
t = offset(st, 0, size);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
t = offset(st, 4, size);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
t = offset(st, 2, size);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
t = offset(st, 3, size);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
t = offset(st, 1, size);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
t = offset(st, 5, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!freeze[index])
|
||||||
|
{
|
||||||
|
if (s[t].inAir == false)
|
||||||
|
{
|
||||||
|
step2[index] = (centerRotation * s[t].rotation) / speed2;
|
||||||
|
|
||||||
|
Vector3 t2 = s[t].pos;
|
||||||
|
t2.x *= walkspeed;
|
||||||
|
// rotate x,y around rotation.
|
||||||
|
if (freeze_y[index])
|
||||||
|
{
|
||||||
|
t2.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
step5[index] = (Quaternion.Euler(0, walkDirection, 0) * t2) / speed2;
|
||||||
|
|
||||||
|
step6[index] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent<Leg>().point;
|
||||||
|
step5[index] = t2 / speed2;
|
||||||
|
|
||||||
|
step6[index] = false;
|
||||||
|
freeze_y[index] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
step5[index] = new Vector3(0, 0, 0);
|
||||||
|
step6[index] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +219,16 @@ public class Walk : MonoBehaviour
|
|||||||
{
|
{
|
||||||
for (int index = 0; index < legs.Count; ++index)
|
for (int index = 0; index < legs.Count; ++index)
|
||||||
{
|
{
|
||||||
legs[index].GetComponent<Leg>().point += step2[index];
|
legs[index].GetComponent<Leg>().point += step5[index];
|
||||||
|
if (step6[index])
|
||||||
|
{
|
||||||
|
//legs[index].GetComponent<Leg>().point += step5[index];
|
||||||
|
|
||||||
|
// rotate x,y around rotation.
|
||||||
|
legs[index].GetComponent<Leg>().setWorldPos(
|
||||||
|
Quaternion.Euler(0, step2[index], 0) * legs[index].GetComponent<Leg>().getWorldPos()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 62866dc69f17c5f40a7ec527e34e82f1
|
guid: a4266f2a53eea3a43972b07e077212bc
|
||||||
timeCreated: 1542141752
|
timeCreated: 1542307321
|
||||||
licenseType: Free
|
licenseType: Free
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
|
|||||||
-131
@@ -1,131 +0,0 @@
|
|||||||
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);
|
|
||||||
step2.Add(0);
|
|
||||||
step3.Add(0);
|
|
||||||
step4.Add(new Vector3(0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
step2[index] = (rotation * s[t].rotation) / speed2;
|
|
||||||
step3[index] = s[t].height / speed2;
|
|
||||||
step4[index] = new Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Vector3 t2 = legsInitial[index] - legs[index].GetComponent<Leg>().point;
|
|
||||||
step4[index] = t2 / speed2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
speed = speed2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
speed--;
|
|
||||||
makestep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 91e6f3895f276d94da1803128e6290e0
|
|
||||||
timeCreated: 1542229569
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
-202
@@ -1,202 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class Walk3 : 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);
|
|
||||||
step2.Add(0);
|
|
||||||
step6.Add(false);
|
|
||||||
//step3.Add(0);
|
|
||||||
//step4.Add(new Vector3(0, 0, 0));
|
|
||||||
step5.Add(new Vector3());
|
|
||||||
|
|
||||||
freeze.Add(false);
|
|
||||||
freeze_y.Add(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct step
|
|
||||||
{
|
|
||||||
public Vector3 pos;
|
|
||||||
public float rotation;
|
|
||||||
public float height;
|
|
||||||
public bool inAir;
|
|
||||||
public bool inRest;
|
|
||||||
|
|
||||||
public step(Vector3 p, float r, float h, bool i, bool ir)
|
|
||||||
{
|
|
||||||
pos = p;
|
|
||||||
rotation = r;
|
|
||||||
height = 0;
|
|
||||||
inAir = i;
|
|
||||||
inRest = ir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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), -1, 0, false, false),
|
|
||||||
|
|
||||||
new step(new Vector3(0, -2, 0), 0, 0, false, false),
|
|
||||||
|
|
||||||
new step(new Vector3(0, 0, 0), 0, 0, false, false), // rest
|
|
||||||
|
|
||||||
new step(new Vector3(1, 0, 0), 1, 0, false, true), // down middle
|
|
||||||
new step(new Vector3(1, 0, 0), 1, 0, false, false),
|
|
||||||
|
|
||||||
new step(new Vector3(0, 0, 0), 0, 0, false, false), // rest
|
|
||||||
|
|
||||||
new step(new Vector3(0, 2, 0), 0, 0, false, false),
|
|
||||||
new step(new Vector3(-1, 0, 0), -1, 0, true, false),
|
|
||||||
};
|
|
||||||
|
|
||||||
public int st = 5;
|
|
||||||
public int speed2 = 30;
|
|
||||||
int speed = 10;
|
|
||||||
|
|
||||||
public float walkDirection = 0;
|
|
||||||
public float centerRotation = 0;
|
|
||||||
|
|
||||||
int size = 8;
|
|
||||||
|
|
||||||
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>();
|
|
||||||
private List<Vector3> step5 = new List<Vector3>();
|
|
||||||
private List<bool> step6 = new List<bool>();
|
|
||||||
|
|
||||||
private List<bool> freeze = new List<bool>();
|
|
||||||
private List<bool> freeze_y = new List<bool>();
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void FixedUpdate()
|
|
||||||
{
|
|
||||||
if (speed <= 0)
|
|
||||||
{
|
|
||||||
if (st >= size-1)
|
|
||||||
st = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
st++;
|
|
||||||
|
|
||||||
if (centerRotation == 0 && walkspeed == 0)
|
|
||||||
{
|
|
||||||
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].inRest)
|
|
||||||
{
|
|
||||||
Vector3 lp = legs[index].GetComponent<Leg>().getLocalPos();// + s[t].pos;
|
|
||||||
//lp.y -= 2;
|
|
||||||
if ((Mathf.Abs(lp.y - (legsInitial[index].y-2)) < 0.0001f)
|
|
||||||
&& (Mathf.Abs(lp.z - legsInitial[index].z) < 0.0001f)
|
|
||||||
&& (Mathf.Abs(lp.x - legsInitial[index].x) < 1.0001f))
|
|
||||||
{
|
|
||||||
freeze[index] = true;
|
|
||||||
freeze_y[index] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*else
|
|
||||||
{
|
|
||||||
freeze[index] = false;
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int index = 0; index < legs.Count; index++)
|
|
||||||
{
|
|
||||||
freeze[index] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int index = 0; index < legs.Count; ++index)
|
|
||||||
{
|
|
||||||
int t = st;
|
|
||||||
if (index == 1 || index == 3 || index == 5)
|
|
||||||
{
|
|
||||||
t = offset(st, 4, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!freeze[index])
|
|
||||||
{
|
|
||||||
if (s[t].inAir == false)
|
|
||||||
{
|
|
||||||
step2[index] = (centerRotation * s[t].rotation) / speed2;
|
|
||||||
|
|
||||||
Vector3 t2 = s[t].pos;
|
|
||||||
t2.x *= walkspeed;
|
|
||||||
// rotate x,y around rotation.
|
|
||||||
if (freeze_y[index])
|
|
||||||
{
|
|
||||||
t2.y = 0;
|
|
||||||
}
|
|
||||||
step5[index] = (Quaternion.Euler(0, walkDirection, 0) * t2) / speed2;
|
|
||||||
|
|
||||||
step6[index] = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent<Leg>().point;
|
|
||||||
step5[index] = t2 / speed2;
|
|
||||||
|
|
||||||
step6[index] = false;
|
|
||||||
freeze_y[index] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
step5[index] = new Vector3(0, 0, 0);
|
|
||||||
step6[index] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
speed = speed2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
speed--;
|
|
||||||
makestep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void makestep()
|
|
||||||
{
|
|
||||||
for (int index = 0; index < legs.Count; ++index)
|
|
||||||
{
|
|
||||||
legs[index].GetComponent<Leg>().point += step5[index];
|
|
||||||
if (step6[index])
|
|
||||||
{
|
|
||||||
//legs[index].GetComponent<Leg>().point += step5[index];
|
|
||||||
|
|
||||||
// rotate x,y around rotation.
|
|
||||||
legs[index].GetComponent<Leg>().setWorldPos(
|
|
||||||
Quaternion.Euler(0, step2[index], 0) * legs[index].GetComponent<Leg>().getWorldPos()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,290 +6,98 @@ InputManager:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Axes:
|
m_Axes:
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Horizontal
|
m_Name: 1
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton: left
|
negativeButton: left
|
||||||
positiveButton: right
|
positiveButton: right
|
||||||
altNegativeButton: a
|
altNegativeButton: a
|
||||||
altPositiveButton: d
|
altPositiveButton: d
|
||||||
gravity: 3
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 3
|
sensitivity: 1
|
||||||
snap: 1
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 2
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Vertical
|
m_Name: 2
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton: down
|
negativeButton: down
|
||||||
positiveButton: up
|
positiveButton: up
|
||||||
altNegativeButton: s
|
altNegativeButton: s
|
||||||
altPositiveButton: w
|
altPositiveButton: w
|
||||||
gravity: 3
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 3
|
sensitivity: 1
|
||||||
snap: 1
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 2
|
||||||
axis: 0
|
axis: 1
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Fire1
|
m_Name: 3
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: left ctrl
|
positiveButton: left ctrl
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton: mouse 0
|
altPositiveButton: mouse 0
|
||||||
gravity: 1000
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1
|
||||||
snap: 0
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 2
|
||||||
axis: 0
|
axis: 2
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Fire2
|
m_Name: 4
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: left alt
|
positiveButton: left alt
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton: mouse 1
|
altPositiveButton: mouse 1
|
||||||
gravity: 1000
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1
|
||||||
snap: 0
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 2
|
||||||
axis: 0
|
axis: 3
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Fire3
|
m_Name: 5
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: left shift
|
positiveButton: left shift
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton: mouse 2
|
altPositiveButton: mouse 2
|
||||||
gravity: 1000
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1
|
||||||
snap: 0
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 2
|
||||||
axis: 0
|
axis: 4
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Jump
|
m_Name: 6
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: space
|
positiveButton: space
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton:
|
altPositiveButton:
|
||||||
gravity: 1000
|
gravity: 1
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Mouse X
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton:
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 0
|
|
||||||
dead: 0
|
|
||||||
sensitivity: 0.1
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 1
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Mouse Y
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton:
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 0
|
|
||||||
dead: 0
|
|
||||||
sensitivity: 0.1
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 1
|
|
||||||
axis: 1
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Mouse ScrollWheel
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton:
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 0
|
|
||||||
dead: 0
|
|
||||||
sensitivity: 0.1
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 1
|
|
||||||
axis: 2
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Horizontal
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton:
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 0
|
|
||||||
dead: 0.19
|
|
||||||
sensitivity: 1
|
sensitivity: 1
|
||||||
snap: 0
|
snap: 1
|
||||||
invert: 0
|
invert: 0
|
||||||
type: 2
|
type: 2
|
||||||
axis: 0
|
axis: 5
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Vertical
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton:
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 0
|
|
||||||
dead: 0.19
|
|
||||||
sensitivity: 1
|
|
||||||
snap: 0
|
|
||||||
invert: 1
|
|
||||||
type: 2
|
|
||||||
axis: 1
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Fire1
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: joystick button 0
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Fire2
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: joystick button 1
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Fire3
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: joystick button 2
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Jump
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: joystick button 3
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton:
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Submit
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: return
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton: joystick button 0
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Submit
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: enter
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton: space
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
|
||||||
- serializedVersion: 3
|
|
||||||
m_Name: Cancel
|
|
||||||
descriptiveName:
|
|
||||||
descriptiveNegativeName:
|
|
||||||
negativeButton:
|
|
||||||
positiveButton: escape
|
|
||||||
altNegativeButton:
|
|
||||||
altPositiveButton: joystick button 1
|
|
||||||
gravity: 1000
|
|
||||||
dead: 0.001
|
|
||||||
sensitivity: 1000
|
|
||||||
snap: 0
|
|
||||||
invert: 0
|
|
||||||
type: 0
|
|
||||||
axis: 0
|
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user