private void ProcessInteractionInput(MVCInput input) { if (input.destroy) { RaycastHit hit; Ray ray = new Ray(camTrans.position, camTrans.forward); if (Physics.Raycast(ray, out hit, interactRange)) { Vector3 blockpos = hit.point; if (blockpos.x % 1.0 == 0 && ray.direction.x < 0) { --blockpos.x; } if (blockpos.y % 1.0 == 0 && ray.direction.y < 0) { --blockpos.y; } if (blockpos.z % 1.0 == 0 && ray.direction.z < 0) { --blockpos.z; } blockpos.x = Mathf.Floor(blockpos.x); blockpos.y = Mathf.Floor(blockpos.y); blockpos.z = Mathf.Floor(blockpos.z); world.DestroyBlock(blockpos); } } if (input.place) { RaycastHit hit; Ray ray = new Ray(camTrans.position, camTrans.forward); if (Physics.Raycast(ray, out hit, interactRange)) { Vector3 blockpos = hit.point; if (blockpos.x % 1.0 == 0 && ray.direction.x > 0) { --blockpos.x; } if (blockpos.y % 1.0 == 0 && ray.direction.y > 0) { --blockpos.y; } if (blockpos.z % 1.0 == 0 && ray.direction.z > 0) { --blockpos.z; } blockpos.x = Mathf.Floor(blockpos.x); blockpos.y = Mathf.Floor(blockpos.y); blockpos.z = Mathf.Floor(blockpos.z); world.AddBlock(blockpos, blockType); } } }
private void ProcessInputAndMotion(MVCInput input, bool doInteractionInput = true) { if (!cc.isGrounded) { yvel -= gravForce * input.dt; } else if (input.jump) { yvel = jumpForce; } else { yvel = 0; } Vector3 move = avatar.up * yvel * input.dt; move += avatar.forward * input.moveZ; move += avatar.right * input.moveX; cc.Move(move); if (avatar.position.y < worldBottom) { avatar.position = world.GetPlayerSpawn(); } avatar.eulerAngles += Vector3.up * input.rotYaw; Vector3 camAng = camTrans.eulerAngles; camAng += Vector3.right * input.rotPitch; if (camAng.x > 180.0f) { camAng.x = Mathf.Clamp(camAng.x, camPitchClamp1, 360.0f); } else if (camAng.x < 10.0f) { camAng.x = Mathf.Clamp(camAng.x, -10.0f, 10.0f); } else { camAng.x = Mathf.Clamp(camAng.x, 0.0f, camPitchClamp2); } camTrans.eulerAngles = camAng; blockType += input.blockTypeChange; while (blockType > numOfBlockTypes || blockType < 1 || !NetBridge.Instance.blockTypeManager.IsBlockPlacable(blockType)) { if (blockType > numOfBlockTypes) { blockType = 1; } else if (blockType < 1) { blockType = numOfBlockTypes; } if (!NetBridge.Instance.blockTypeManager.IsBlockPlacable(blockType)) { blockType += input.blockTypeChange; } } if (isLocalPlayer && input.blockTypeChange != 0) { UIBridge.Instance.OnBlockSelectionChange(blockType); } if (doInteractionInput) { ProcessInteractionInput(input); } }