public void Jump() { if (Rigidbody && state == PlayerState.Landed) { var currentBlock = GameManager.Instance.currentBlockController; var nextBlock = GameManager.Instance.currentBlockController.nextBlock; if (currentBlock != null && nextBlock != null) { Rigidbody.drag = 0f; var target = nextBlock.prefectLandingPoint; var blockAngle = currentBlock.Angle; var jumpAngle = Random.Range(GameManager.Instance.Data.JumpMinAngle, GameManager.Instance.Data.JumpMaxAngle); var vel = PhysicMath.CalculateVelocity(transform, target, jumpAngle); // correct velocity for over jump if (blockAngle < GameManager.Instance.Data.OverjumpAnglesTopLimit && blockAngle > GameManager.Instance.Data.OverjumpAnglesBottomLimit) { Debug.LogError("+++ over jump"); vel = vel * 1.05f; } // correct velocity for under jump if (blockAngle < GameManager.Instance.Data.UnderjumpAnglesTopLimit && blockAngle > GameManager.Instance.Data.UnderjumpAnglesBottomLimit) { Debug.LogError("+++ under jump"); vel = vel * 0.9f; } // limit velocity if angle too high if (blockAngle > GameManager.Instance.Data.OptimalAnglesTopLimit) { Debug.LogError("+++ too high jump"); vel = vel * 0.9f; } Rigidbody.velocity = vel; state = PlayerState.Jumped; } } }
public void Update() { //TimerManager.Update(Time.deltaTime); if (Input.GetKeyUp(KeyCode.G)) { var ground = _poolGrounds.Get(); if (ground) { EventManager.testVoidEvent(); ground.transform.localScale = _groundScale; ground.transform.position = Vector3.zero; _grounds.Add(ground); } } if (Input.GetKeyUp(KeyCode.H)) { if (_grounds.Count > 0) { var index = Random.Range(0, _grounds.Count); _poolGrounds.Release(_grounds[index]); _grounds.RemoveAt(index); } } if (Input.GetKeyUp(KeyCode.J)) { var rigbody = _velocityObject.GetComponent <Rigidbody>(); if (rigbody != null) { rigbody.velocity = PhysicMath.CalculateVelocity(_velocityObject, _target, 60f); debug = true; } } if (debug) { Debug.LogError("+++ " + _target.position + " / " + _velocityObject.position + " *** " + Vector3.Distance(_target.position, _velocityObject.position)); } //var direction = target.position - velocityObject.position; //Debug.DrawLine(_velocityObject.position, direction, Color.yellow); }