void Update() { float waveslice = 0.0f; float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); if (Mathf.Abs(horizontal) == 0f && Mathf.Abs(vertical) == 0f) { timer = 0.0f; } else { waveslice = Mathf.Sin(timer); timer += bobbingSpeed * Time.deltaTime * Mathf.PI * 2f * (Input.GetButton("Run") ? 1f : 0.5f); if (timer > Mathf.PI * 2f) { timer = timer - (Mathf.PI * 2f); } } if (waveslice != 0f) { float translateChange = waveslice * bobbingAmount; float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); totalAxes = Mathf.Clamp(totalAxes, 0.0f, 1.0f); translateChange = totalAxes * translateChange; Vector3 localPos = transform.localPosition; localPos.y = midpoint + translateChange * Time.timeScale; if (!player.isJumping() && !player.isFalling() && (localPos.y > midpoint && last <= midpoint) || (localPos.y < midpoint && last >= midpoint)) { stepSound.pitch = Random.Range(0.8f, 1.2f); stepSound.Play(); } transform.localPosition = localPos; last = localPos.y; } else { Vector3 localPos = transform.localPosition; localPos.y = midpoint; transform.localPosition = localPos; } }
// Update is called once per frame void Update() { for (var i = 0; i < meshes.Count; ++i) { var mesh = meshes[i]; Transform target = armOut[i]; if (drifter.isFalling()) { target = armUp[i]; } else if (drifter.isJumping()) { target = armDown[i]; } Quaternion a = mesh.transform.rotation; mesh.transform.LookAt(target); mesh.transform.rotation = Quaternion.Slerp(a, mesh.transform.rotation, 0.03f); } container.transform.rotation = Quaternion.Slerp(container.transform.rotation, cam.transform.rotation, 0.5f); }