5dof joysticks and Digging Mechanic
This commit is contained in:
parent
57c47c815f
commit
642a863f1a
2 changed files with 68 additions and 12 deletions
|
@ -61,10 +61,12 @@ public class Monolith : MonoBehaviour
|
|||
simulate.Step(this);
|
||||
}
|
||||
|
||||
InputDevice headset;
|
||||
InputDevice headset, offCon, mainCon;
|
||||
void Start()
|
||||
{
|
||||
headset = InputDevices.GetDeviceAtXRNode(XRNode.Head);
|
||||
offCon = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
|
||||
mainCon = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
|
||||
|
||||
testPos = piece.pos + Vector3.forward * 0.4f;
|
||||
testVel = Vector3.down;
|
||||
|
@ -90,7 +92,7 @@ public class Monolith : MonoBehaviour
|
|||
}
|
||||
|
||||
Vector3 testPos;
|
||||
Vector3Int voxelPos(Vector3 pos)
|
||||
Vector3Int VoxelPos(Vector3 pos)
|
||||
{
|
||||
return new Vector3Int(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y), Mathf.RoundToInt(pos.z));
|
||||
}
|
||||
|
@ -106,7 +108,7 @@ public class Monolith : MonoBehaviour
|
|||
{
|
||||
Vector3 d = (Vector3)allDirs[i] * 0.2f;
|
||||
d[axis] = 0;
|
||||
Vector3 vPos = Voxelcast(voxelPos(pos + d), step);
|
||||
Vector3 vPos = Voxelcast(VoxelPos(pos + d), step);
|
||||
float dist = Mathf.Abs(vPos[axis] - pos[axis]);
|
||||
if (dist < closest)
|
||||
{
|
||||
|
@ -141,6 +143,8 @@ public class Monolith : MonoBehaviour
|
|||
float delay;
|
||||
[ReadOnly]
|
||||
public bool movePiece;
|
||||
[ReadOnly]
|
||||
public Vector3 voxelCenter;
|
||||
void Update()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
|
@ -153,20 +157,64 @@ public class Monolith : MonoBehaviour
|
|||
{
|
||||
camForm.rotation = headsetRot;
|
||||
}
|
||||
camForm.position = camForm.rotation * Vector3.back * 10;
|
||||
camForm.position = voxelCenter + (camForm.rotation * Vector3.back * 10);
|
||||
|
||||
// cursor
|
||||
Quaternion mainRot = Quaternion.identity;
|
||||
mainCon.TryGetFeatureValue(CommonUsages.deviceRotation, out mainRot);
|
||||
|
||||
InputDevice mainCon = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
|
||||
Vector2 wasd = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
||||
Vector2 joystick = Vector2.zero;
|
||||
mainCon.TryGetFeatureValue(CommonUsages.primary2DAxis, out joystick);
|
||||
Vector2 mainStick = Vector2.zero;
|
||||
mainCon.TryGetFeatureValue(CommonUsages.primary2DAxis, out mainStick);
|
||||
Vector3 mainDir = new Vector3(mainStick.x, 0, mainStick.y);
|
||||
if (mainDir.sqrMagnitude > 0)
|
||||
{
|
||||
mainRot *= Quaternion.LookRotation(mainDir);
|
||||
}
|
||||
|
||||
Vector2 input = wasd + joystick;
|
||||
Vector3 mainCursor = testPos + (mainRot * Vector3.forward);
|
||||
Vector3Int cvPos = VoxelPos(mainCursor);
|
||||
|
||||
testVel.x += input.x * 6 * Time.deltaTime;
|
||||
testVel.z += input.y * 6 * Time.deltaTime;
|
||||
bool mainTrigger = false;
|
||||
mainCon.TryGetFeatureValue(CommonUsages.triggerButton, out mainTrigger);
|
||||
if (mainTrigger)
|
||||
{
|
||||
if (!InVoxel(cvPos))
|
||||
{
|
||||
voxels[vIndex].pos = cvPos;
|
||||
vIndex++;
|
||||
if (vIndex == voxels.Length) { vIndex = 0; }
|
||||
|
||||
if (input.sqrMagnitude == 0)
|
||||
simulate.Step(this);
|
||||
}
|
||||
}
|
||||
|
||||
Graphics.DrawMesh(render.meshPieceDebug,
|
||||
mainCursor, Quaternion.identity,
|
||||
render.matPieceDebug, 0
|
||||
);
|
||||
|
||||
if (!InVoxel(cvPos))
|
||||
Graphics.DrawMesh(render.meshPieceDebug,
|
||||
cvPos, Quaternion.identity,
|
||||
render.matPieceDebug, 0
|
||||
);
|
||||
|
||||
// Movement
|
||||
Quaternion offRot = Quaternion.identity;
|
||||
offCon.TryGetFeatureValue(CommonUsages.deviceRotation, out offRot);
|
||||
|
||||
Vector2 offStick = Vector2.zero;
|
||||
offCon.TryGetFeatureValue(CommonUsages.primary2DAxis, out offStick);
|
||||
offStick += new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
||||
Vector3 offDir = new Vector3(offStick.x, 0, offStick.y);
|
||||
if (offDir.sqrMagnitude > 0)
|
||||
{
|
||||
offRot *= Quaternion.LookRotation(offDir);
|
||||
}
|
||||
|
||||
testVel += offRot * Vector3.forward * offStick.magnitude * 6 * Time.deltaTime;
|
||||
|
||||
if (offStick.sqrMagnitude == 0)
|
||||
{
|
||||
testVel.x *= 1 - (60 * Time.deltaTime);
|
||||
testVel.z *= 1 - (60 * Time.deltaTime);
|
||||
|
|
|
@ -9,6 +9,14 @@ public class Simulate
|
|||
public void Step(Monolith mono)
|
||||
{
|
||||
generate.Step(mono);
|
||||
|
||||
Vector3 center = Vector3.zero;
|
||||
for (int i = 0; i < mono.voxels.Length; i++)
|
||||
{
|
||||
center += mono.voxels[i].pos;
|
||||
}
|
||||
|
||||
mono.voxelCenter = center / mono.voxels.Length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue