v8 added walking and rotation at the same time :D
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+26
-2
@@ -14098,7 +14098,7 @@ Transform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 94996747}
|
m_GameObject: {fileID: 94996747}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -20, y: -15, z: 11}
|
m_LocalPosition: {x: -20, y: -17, z: 11}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 379804153}
|
- {fileID: 379804153}
|
||||||
@@ -48707,6 +48707,7 @@ GameObject:
|
|||||||
- component: {fileID: 311513962}
|
- component: {fileID: 311513962}
|
||||||
- component: {fileID: 311513963}
|
- component: {fileID: 311513963}
|
||||||
- component: {fileID: 311513964}
|
- component: {fileID: 311513964}
|
||||||
|
- component: {fileID: 311513965}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: RotationControl
|
m_Name: RotationControl
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -48738,7 +48739,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 30ea8dc0510444c42ae4b4db1f5ee2bd, type: 3}
|
m_Script: {fileID: 11500000, guid: 30ea8dc0510444c42ae4b4db1f5ee2bd, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
transformation: {x: 0, y: 2, z: 0}
|
transformation: {x: 0, y: 0, z: 0}
|
||||||
transformation2: {x: 0, y: 0, z: 0}
|
transformation2: {x: 0, y: 0, z: 0}
|
||||||
rotation: {x: 0, y: 0, z: 0, w: 0}
|
rotation: {x: 0, y: 0, z: 0, w: 0}
|
||||||
rotation2:
|
rotation2:
|
||||||
@@ -48793,6 +48794,29 @@ MonoBehaviour:
|
|||||||
st: 5
|
st: 5
|
||||||
speed2: 1
|
speed2: 1
|
||||||
rotation: 5
|
rotation: 5
|
||||||
|
--- !u!114 &311513965
|
||||||
|
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: a4266f2a53eea3a43972b07e077212bc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
legs:
|
||||||
|
- {fileID: 636309705}
|
||||||
|
- {fileID: 596626244}
|
||||||
|
- {fileID: 1619174560}
|
||||||
|
- {fileID: 1453644144}
|
||||||
|
- {fileID: 1772413224}
|
||||||
|
- {fileID: 210611261}
|
||||||
|
st: 5
|
||||||
|
speed2: 10
|
||||||
|
walkDirection: 0
|
||||||
|
centerRotation: 0
|
||||||
|
walkspeed: 0
|
||||||
--- !u!1 &311874317
|
--- !u!1 &311874317
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
+143
@@ -0,0 +1,143 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct step
|
||||||
|
{
|
||||||
|
public Vector3 pos;
|
||||||
|
public float rotation;
|
||||||
|
public float height;
|
||||||
|
public bool inAir;
|
||||||
|
|
||||||
|
public step(Vector3 p, float r, float h, bool i)
|
||||||
|
{
|
||||||
|
pos = p;
|
||||||
|
rotation = r;
|
||||||
|
height = 0;
|
||||||
|
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(new Vector3(-1, 0, 0), -1, 0, false),
|
||||||
|
|
||||||
|
new step(new Vector3(0, -2, 0), 0, -2, false),
|
||||||
|
|
||||||
|
new step(new Vector3(0, 0, 0), 0, 0, false), // rest
|
||||||
|
|
||||||
|
new step(new Vector3(1, 0, 0), 1, 0, false),
|
||||||
|
new step(new Vector3(1, 0, 0), 1, 0, false),
|
||||||
|
|
||||||
|
new step(new Vector3(0, 0, 0), 0, 0, false), // rest
|
||||||
|
|
||||||
|
new step(new Vector3(0, 2, 0), 0, 2, false),
|
||||||
|
new step(new Vector3(-1, 0, 0), -1, 0, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
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>();
|
||||||
|
|
||||||
|
// 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] = (centerRotation * s[t].rotation) / speed2;
|
||||||
|
|
||||||
|
Vector3 t2 = s[t].pos;
|
||||||
|
t2.x *= walkspeed;
|
||||||
|
// rotate x,y around rotation.
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a4266f2a53eea3a43972b07e077212bc
|
||||||
|
timeCreated: 1542307321
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user