diff --git a/Assets/Monolith.cs b/Assets/Monolith.cs index 7f18931..4ee4cd3 100644 --- a/Assets/Monolith.cs +++ b/Assets/Monolith.cs @@ -14,7 +14,8 @@ public class Monolith : MonoBehaviour public Worm leftWorm, rightWorm; - public VoxelObject[] voxelObjects; + public VoxelObject player; + public VoxelObject pump; public Simulate simulate = new Simulate(); public Vhysics vhysics = new Vhysics(); @@ -79,16 +80,6 @@ public class Monolith : MonoBehaviour return false; } - - bool jumpBtn = false; - - - Vector3 onTouchPos, oldTouchPos; - Vector2 camAngle = new Vector2(30, 45); - Vector2 camAngleVel, oldCamAngleVel; - float delay; - [ReadOnly] - public bool movePiece; [ReadOnly] public Vector3 voxelCenter; void Update() @@ -105,9 +96,6 @@ public class Monolith : MonoBehaviour } camForm.position = voxelCenter + (camForm.rotation * Vector3.back * 10); - // player - VoxelObject player = voxelObjects[0]; - // cursor Quaternion mainRot = Quaternion.identity; mainCon.TryGetFeatureValue(CommonUsages.deviceRotation, out mainRot); @@ -123,6 +111,15 @@ public class Monolith : MonoBehaviour Vector3 mainCursor = player.pos + (mainRot * Vector3.forward); Vector3Int cvPos = VoxelPos(mainCursor); + // throwing + bool btnThrow = false; + mainCon.TryGetFeatureValue(CommonUsages.primaryButton, out btnThrow); + if (btnThrow) + { + pump.pos = player.pos; + pump.voxelBody.velocity = mainRot * Vector3.forward * 10; + } + // mining bool mainTrigger = false; mainCon.TryGetFeatureValue(CommonUsages.triggerButton, out mainTrigger); @@ -172,7 +169,8 @@ public class Monolith : MonoBehaviour } // jumping ? - mainCon.TryGetFeatureValue(CommonUsages.primaryButton, out jumpBtn); + bool jumpBtn = false; + offCon.TryGetFeatureValue(CommonUsages.triggerButton, out jumpBtn); if (Input.GetKeyDown(KeyCode.Space) || (jumpBtn && Mathf.Abs(vel.y) < 0.1f)) { vel.y = 8; @@ -189,9 +187,13 @@ public class Monolith : MonoBehaviour // the refactoring needs to be reconsidered // I don't want an arbitrary list of VoxelObjects // I'd like a Player - // an array of each enemy type + // an array of each enemy type (I want them to be deeply unique) // an array of any/each physics object + // just deliberate what needs to physicsed in the vphysics Update method + + // goal a physics object the player can throw in the direction of the cursor (auto retrieve) + vhysics.Update(); render.Update(); } @@ -270,6 +272,13 @@ public class VoxelObject public VoxelBody voxelBody; public Mesh mesh; + [HideInInspector] public Matrix4x4 m4; + + public void Draw(Material mat) + { + m4.SetTRS(pos, rot, Vector3.one * scale); + Graphics.DrawMesh(mesh, m4, mat, 0); + } } [Serializable] diff --git a/Assets/Render.cs b/Assets/Render.cs index 5a67fc2..2ae169f 100644 --- a/Assets/Render.cs +++ b/Assets/Render.cs @@ -27,30 +27,16 @@ public class Render { Voxels(); - for (int i = 0; i < mono.voxelObjects.Length; i++) - { - VoxelObject voxelObject = mono.voxelObjects[i]; - // render voxelbody bounds - if (voxelObject.voxelBody != null) - { - tempM4.SetTRS( - voxelObject.pos, - Quaternion.identity, - Vector3.one * voxelObject.voxelBody.boundRadius * 2 - ); - Graphics.DrawMesh(meshCube, tempM4, matBounds, 0); - } + mono.player.Draw(matObject); + mono.pump.Draw(matObject); - // render voxelobject mesh - if (voxelObject.mesh != null) - { - voxelObject.rot.Normalize(); - Graphics.DrawMesh(voxelObject.mesh, - voxelObject.pos, voxelObject.rot, - matObject, 0 - ); - } - } + // Render vhysics bounds + // tempM4.SetTRS( + // voxelObject.pos, + // Quaternion.identity, + // Vector3.one * voxelObject.voxelBody.boundRadius * 2 + // ); + // Graphics.DrawMesh(meshCube, tempM4, matBounds, 0); // Draw Enemy // Graphics.DrawMesh(meshPieceDebug, diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index f9c72d2..6c33ab5 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -220,14 +220,56 @@ MonoBehaviour: rightWorm: pos: {x: 1, y: 2, z: 5} dirIndex: 4 - voxelObjects: - - pos: {x: 0, y: 0, z: 0} + player: + pos: {x: 0, y: 0, z: 0} rot: {x: 0, y: 0, z: 0, w: 1} scale: 1 voxelBody: - boundRadius: 0.32 + boundRadius: 0.3 velocity: {x: 0, y: 0, z: 0} mesh: {fileID: 8102167970221282723, guid: f17ff0e1c561a0a4bba0f4c3bb139cc4, type: 3} + m4: + e00: 0 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 0 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 0 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 0 + pump: + pos: {x: 0, y: 0, z: 0} + rot: {x: 0, y: 0, z: 0, w: 1} + scale: 0.5 + voxelBody: + boundRadius: 0.1 + velocity: {x: 0, y: 0, z: 0} + mesh: {fileID: 8102167970221282723, guid: f17ff0e1c561a0a4bba0f4c3bb139cc4, type: 3} + m4: + e00: 0 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 0 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 0 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 0 render: meshVoxelDebug: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} meshPieceDebug: {fileID: 8102167970221282723, guid: f17ff0e1c561a0a4bba0f4c3bb139cc4, @@ -239,7 +281,6 @@ MonoBehaviour: matEnemy: {fileID: 2100000, guid: d9312e72de6721d41975fc093421fc2f, type: 2} matPath: {fileID: 2100000, guid: 525b9c2ebdaac4440b94ea0fa8ca42dd, type: 2} cam: {fileID: 963194227} - movePiece: 0 voxelCenter: {x: 0, y: 0, z: 0} dirs: - {x: -1, y: 0, z: 0} diff --git a/Assets/Vhysics.cs b/Assets/Vhysics.cs index cedd59c..b93b9c2 100644 --- a/Assets/Vhysics.cs +++ b/Assets/Vhysics.cs @@ -18,73 +18,56 @@ public class Vhysics public void Update() { // bounds - for (int i = 0; i < mono.voxelObjects.Length; i++) - { - VoxelObject vobj = mono.voxelObjects[i]; - - if (vobj.voxelBody != null) - { - Vector3 toPos = vobj.pos + vobj.voxelBody.velocity * Time.deltaTime; - - int w = 0; - while (w < 3) - { - Vector3 clampPos = new Vector3( - Mathf.Clamp(toPos.x, Bound(vobj, 0, -1), Bound(vobj, 0, 1)), - Mathf.Clamp(toPos.y, Bound(vobj, 1, -1), Bound(vobj, 1, 1)), - Mathf.Clamp(toPos.z, Bound(vobj, 2, -1), Bound(vobj, 2, 1)) - ); - - float largest = 0; - int largeIndex = -1; - for (int j = 0; j < 3; j++) - { - float dist = Mathf.Abs(toPos[j] - clampPos[j]); - if (dist > largest) - { - largeIndex = j; - largest = dist; - } - } - - if (largeIndex > -1) - { - toPos[largeIndex] = clampPos[largeIndex]; - vobj.voxelBody.velocity[largeIndex] *= -0.25f; // Bounce - } - else - { - break; - } - - w++; - } - - vobj.pos = toPos; - - - // hit checks - for (int j = 0; j < mono.voxelObjects.Length; j++) - { - // space voxelBodys - VoxelObject otherObject = mono.voxelObjects[j]; - if (i != j && otherObject.voxelBody != null) - { - Vector3 delta = otherObject.pos - vobj.pos; - // if (delta.magnitude < ) - // { - // otherObject.voxelBody.velocity += ; - // } - } - } - } - } + VoxelCollision(mono.player); + VoxelCollision(mono.pump); // FAT + // hit callbacks // rectangular bounds // larger than one voxel } + public void VoxelCollision(VoxelObject vobj) + { + Vector3 toPos = vobj.pos + vobj.voxelBody.velocity * Time.deltaTime; + + int w = 0; + while (w < 3) + { + Vector3 clampPos = new Vector3( + Mathf.Clamp(toPos.x, Bound(vobj, 0, -1), Bound(vobj, 0, 1)), + Mathf.Clamp(toPos.y, Bound(vobj, 1, -1), Bound(vobj, 1, 1)), + Mathf.Clamp(toPos.z, Bound(vobj, 2, -1), Bound(vobj, 2, 1)) + ); + + float largest = 0; + int largeIndex = -1; + for (int j = 0; j < 3; j++) + { + float dist = Mathf.Abs(toPos[j] - clampPos[j]); + if (dist > largest) + { + largeIndex = j; + largest = dist; + } + } + + if (largeIndex > -1) + { + toPos[largeIndex] = clampPos[largeIndex]; + vobj.voxelBody.velocity[largeIndex] *= -0.25f; // Bounce + } + else + { + break; + } + + w++; + } + + vobj.pos = toPos; + } + public float Bound(VoxelObject vobj, int axis, int dir) { Vector3Int step = Vector3Int.zero;