void OnTriggerStay(Collider other) { VehicleControllerV3 otherVehicleController = null; // Check if there's an attached rigidbody first so we don't throw an error if (other.attachedRigidbody) { otherVehicleController = other.attachedRigidbody.transform.GetComponent <VehicleControllerV3>(); } if (otherVehicleController && otherVehicleController.currentPassengerTransform != null) { if (other.attachedRigidbody.velocity.magnitude <= maxSpeedForDropoff) { Transform theirPassenger = otherVehicleController.currentPassengerTransform; otherVehicleController.currentPassengerTransform.parent = null; otherVehicleController.currentPassengerTransform = null; meshCollider.enabled = false; if (otherVehicleController.GetComponent <PlayerInput>().isPlayer2) { GameManager.Instance.AddToScore(false); } else { GameManager.Instance.AddToScore(true); } StartCoroutine(MovePassengerToDropoffPointCoroutine(transform, theirPassenger)); } } }
void OnCollisionEnter(Collision collision) { if (!isStealable) { return; } Rigidbody otherRigidbody = collision.collider.attachedRigidbody; if (myVehicleController.currentPassengerTransform != null && otherRigidbody) { VehicleControllerV3 otherVehicleController = otherRigidbody.GetComponent <VehicleControllerV3>(); if (otherVehicleController && otherVehicleController.GetComponent <StealChecker>().isStealable) { if (collision.impulse.magnitude > minImpulseToSteal) { if (GetComponent <PlayerInput>().isPlayer2) { Debug.Log("Impulse force: " + collision.impulse.magnitude); } if (GetComponent <PlayerInput>().isPlayer2) { Debug.Log("OtherRB: ", myVehicleController.currentPassengerTransform); } if (GetComponent <PlayerInput>().isPlayer2) { Debug.Log("OtherVehicleController: ", otherVehicleController.gameObject); } if (GetComponent <PlayerInput>().isPlayer2) { Debug.Log("my VehicleController: ", myVehicleController.gameObject); } StartCoroutine(MovePassengerToOtherVehicleCoroutine(myVehicleController.currentPassengerTransform, otherVehicleController.passengerLocation)); myVehicleController.currentPassengerTransform.parent = otherRigidbody.transform; otherVehicleController.currentPassengerTransform = myVehicleController.currentPassengerTransform; myVehicleController.currentPassengerTransform = null; isStealable = false; Invoke("MakeStealable", stealableRechargeTime); } } } }
void OnTriggerStay(Collider other) { VehicleControllerV3 otherVehicleController = null; // Check if there's an attached rigidbody first so we don't throw an error if (other.attachedRigidbody) { otherVehicleController = other.attachedRigidbody.transform.GetComponent <VehicleControllerV3>(); } if (otherVehicleController) { if (other.attachedRigidbody.velocity.magnitude <= maxSpeedForPickup) { meshRenderer.enabled = false; transform.parent.parent = other.attachedRigidbody.transform; meshCollider.enabled = false; otherVehicleController.currentPassengerTransform = transform.parent; StartCoroutine(MovePassengerToCarCoroutine(otherVehicleController.passengerLocation)); } } }
// Start is called before the first frame update void Start() { myVehicleController = transform.GetComponent <VehicleControllerV3>(); }