private void Awake() { SelfRigidbody = GetComponent <Rigidbody>(); SelfInput = GetComponent <InputManager>(); PlayerTransform = GetComponentInParent <PlayerAcceleration>().GetComponent <Transform>(); SelfPlayerAcceleration = GetComponentInParent <PlayerAcceleration>(); }
private void OnCollisionEnter(Collision collision) { PlayerMove collisionMove = collision.gameObject.GetComponent <PlayerMove>(); PlayerAcceleration collisionAcceleration = collision.gameObject.GetComponentInParent <PlayerAcceleration>(); if (collision.gameObject.CompareTag("Player")) { playerSonorEffectsAS.clip = collisionAC; playerSonorEffectsAS.pitch = Random.Range(0.9f, 1.1f); playerSonorEffectsAS.Play(); float selfSideSpeed = Mathf.Abs(CalculedVelocity.x) + Mathf.Abs(CalculedVelocity.y) + Mathf.Abs(CalculedVelocity.z); float collisionSideSpeed = Mathf.Abs(collisionMove.CalculedVelocity.x) + Mathf.Abs(collisionMove.CalculedVelocity.y) + Mathf.Abs(collisionMove.CalculedVelocity.z); float sideSpeedDif = selfSideSpeed - collisionSideSpeed; if (sideSpeedDif > 5) { collisionAcceleration.ForwardSpeed -= CollisionSpeedReduce.Value; } else if (sideSpeedDif < -5) { SelfPlayerAcceleration.ForwardSpeed -= CollisionSpeedReduce.Value; } else { float forwardSpeedDif = SelfPlayerAcceleration.ForwardSpeed - collisionAcceleration.ForwardSpeed; if (forwardSpeedDif > 0) { collisionAcceleration.ForwardSpeed -= CollisionSpeedReduce.Value; } else { SelfPlayerAcceleration.ForwardSpeed -= CollisionSpeedReduce.Value; } } } }
private void Awake() { SelfPlayerAcceleration = GetComponentInParent <PlayerAcceleration>(); SelfPlayerObject = GetComponentInChildren <PlayerObject>(); }