public void CurveShoot(PassController _passController, PawnController _thrower, PawnController _target, BallDatas _passDatas, Vector3 _lookDirection) //Shoot a curve ball to reach a point { if (ballCoroutine != null) { StopCoroutine(ballCoroutine); } startPosition = _passController.GetHandTransform().position; transform.SetParent(null, true); transform.localScale = Vector3.one; ballInformations.thrower = _thrower; ballInformations.moveSpeed = _passDatas.moveSpeed; ballInformations.maxDistance = Mathf.Infinity; ballInformations.ballDatas = _passDatas; ballInformations.bounceCount = 0; ballInformations.canBounce = true; ballInformations.canHitWalls = true; ballInformations.curve = _passController.GetCurvedPathCoordinates(startPosition, _target, _lookDirection, out float d); ballInformations.timeFlying = 0; ballInformations.initialLookDirection = _lookDirection; ballInformations.isTeleguided = false; hitGameObjects.Clear(); ChangeState(BallState.Flying); UpdateColor(); }
private void UpdateBallPosition() { switch (ballInformations.state) { case BallState.Flying: ballInformations.timeFlying += Time.deltaTime; if (ballInformations.isTeleguided) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); if (i_currentPassController != null) { ballInformations.direction = (i_currentPassController.GetTarget().GetCenterPosition() - transform.position).normalized; } } else if (ballInformations.curve != null) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); List <Vector3> i_pathCoordinates = i_currentPassController.GetCurvedPathCoordinates(startPosition, i_currentPassController.GetTarget(), ballInformations.initialLookDirection, out float d); float i_curveLength; if (i_currentPassController == null) { return; } ConvertCoordinatesToCurve(i_pathCoordinates, out curveX, out curveY, out curveZ, out i_curveLength); ballInformations.maxDistance = i_curveLength; float i_positionOnCurve = ballInformations.distanceTravelled / ballInformations.maxDistance; if (ballInformations.thrower.isPlayer) { LockManager.LockTargetsInPath(i_pathCoordinates, i_positionOnCurve); if (i_positionOnCurve >= 0.95f) { ChangeState(BallState.Grounded); LockManager.UnlockAll(); } } Vector3 i_nextPosition = new Vector3(curveX.Evaluate(i_positionOnCurve + 0.1f), curveY.Evaluate(i_positionOnCurve + 0.1f), curveZ.Evaluate(i_positionOnCurve + 0.1f)); ballInformations.direction = i_nextPosition - transform.position; } if (ballInformations.moveSpeed <= 0) { ballInformations.curve = null; ChangeState(BallState.Grounded); } else { //Ball is going to it's destination, checking for collisions RaycastHit[] i_hitColliders = Physics.RaycastAll(transform.position, ballInformations.direction, ballInformations.moveSpeed * Time.deltaTime); foreach (RaycastHit raycast in i_hitColliders) { /*EnemyShield i_selfRef = raycast.collider.GetComponentInParent<EnemyShield>(); * if (i_selfRef != null) * { * if (i_selfRef.shield.transform.InverseTransformPoint(transform.position).z > 0.0) * { * FeedbackManager.SendFeedback("event.ShieldHitByBall", this); * Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_selfRef.shield.transform.forward); * Bounce(i_newDirection, 1); * } * }*/ IHitable i_potentialHitableObjectFound = raycast.collider.GetComponent <IHitable>(); if (i_potentialHitableObjectFound != null && !hitGameObjects.Contains(i_potentialHitableObjectFound) && !isGhostBall) { hitGameObjects.Add(i_potentialHitableObjectFound); i_potentialHitableObjectFound.OnHit(this, ballInformations.direction * ballInformations.moveSpeed, ballInformations.thrower, GetCurrentDamages(), DamageSource.Ball); SlowTimeScale(); } if (raycast.collider.isTrigger || raycast.collider.gameObject.layer != LayerMask.NameToLayer("Environment")) { break; } FeedbackManager.SendFeedback("event.WallHitByBall", raycast.transform, raycast.point, ballInformations.direction, raycast.normal); if (!ballInformations.canHitWalls) { return; } if (ballInformations.bounceCount < ballInformations.ballDatas.maxBounces && ballInformations.canBounce) //Ball can bounce: Bounce { Analytics.CustomEvent("BallBounce", new Dictionary <string, object> { { "Zone", GameManager.GetCurrentZoneName() }, }); Vector3 i_hitNormal = raycast.normal; i_hitNormal.y = 0; Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_hitNormal); i_newDirection.y = -ballInformations.direction.y; Bounce(i_newDirection, ballInformations.ballDatas.speedMultiplierOnBounce); return; } else //Ball can't bounce: Stop { ChangeState(BallState.Grounded); MomentumManager.DecreaseMomentum(MomentumManager.datas.momentumLossWhenBallHitTheGround); return; } } } transform.position += ballInformations.direction.normalized * ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); ballInformations.distanceTravelled += ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); if (ballInformations.curve == null && !ballInformations.isTeleguided && ballInformations.distanceTravelled >= ballInformations.maxDistance) { ChangeState(BallState.Grounded); } break; } }