void Update() { bool place = controls.Player.Place.ReadValue <float>() == 1; bool mine = controls.Player.Mine.ReadValue <float>() == 1; bool clicking = mine || place; if (clicking && (DateTimeOffset.Now.ToUnixTimeMilliseconds() - last >= DELAY || !used)) { var c = PlayerLook.GetRotation(); Vector3 dir = c * Vector3.forward; if (Physics.Raycast(Camera.main.transform.position, dir, out RaycastHit hit, interactDist, groundLayer)) { used = true; if (place) { dir *= -1; } Vector3 target = hit.point + dir * .01f; if (place && CannotPlace(target, player.position)) { return; } ChunkPos pos = terrainGenerator.GetChunkPosition(target); TerrainChunk tc = terrainGenerator.GetChunkAt(pos); int bix = Mathf.FloorToInt(target.x) - pos.x + 1; int biy = Mathf.FloorToInt(target.y); int biz = Mathf.FloorToInt(target.z) - pos.z + 1; if (mine) { if (CanBreak(tc.Blocks[bix, biy, biz])) { tc.Blocks[bix, biy, biz] = BlockType.Air; } } else { tc.Blocks[bix, biy, biz] = inventory.Current; } last = DateTimeOffset.Now.ToUnixTimeMilliseconds(); tc.BuildMesh(); } } if (!clicking) { used = false; } }
void Update() { if (transform.position.y < -20) { transform.position += new Vector3(1, 200, 1); return; } Vector2 input = controls.Player.Move.ReadValue <Vector2>(); float x = input.x; float z = input.y; bool sprint = controls.Player.Sprint.ReadValue <float>() == 1; bool jump = controls.Player.Jump.ReadValue <float>() == 1; var c = PlayerLook.GetRotation(); Vector3 dir = c * Vector3.right * x + c * Vector3.forward * z; bool grounded = IsOnGround(); if (!grounded) { dir *= .7f; } float actualSpeed = speed; if (sprint) { actualSpeed *= sprintMultiplier; } dir *= actualSpeed; if (jump && grounded) { directionY = jumpSpeed; } if (!grounded) { directionY -= g * 1.4f * Time.deltaTime; } else if (directionY < 0) { directionY = -g / 2; } dir.y = directionY; cntrl.Move(dir * Time.deltaTime); }
private IEnumerator Move() { player.position += new Vector3(0, 250, 0); yield return(new WaitForFixedUpdate()); Quaternion rot = PlayerLook.GetRotation(); Vector3 dir = rot * Vector3.forward; transform.position = player.position + dir * 20; transform.rotation = rot; }