// Resets the disc position and state public void ResetDisc() { if (!isServer) { return; // Only let server reset disc } useDiscBody(true); discBody.detectCollisions = true; discBody.velocity = Vector3.zero; discBody.angularVelocity = Vector3.zero; discState = DiscState.FLIGHT; transform.position = new Vector3(0, 5, 0); }
/// <summary> /// Changes the current state /// Applies any logic for then new state to take effect /// </summary> /// <param name="state"></param> public void ChangeState(DiscState state) { State = state; ElementalState = DiscElementalState.None; switch (state) { case DiscState.Attached: AttachToPlayer(); break; case DiscState.Breaking: TriggerBreakRoutine(); break; case DiscState.Dispensed: AttachToDispenser(); break; case DiscState.Connected: AttachToPowerStation(); break; case DiscState.Caught: StopDisc(); player.TriggerCatchingRoutine(true); break; case DiscState.Charging: TriggerChargingRoutine(); break; case DiscState.Fired: trailRenderer.enabled = true; trailRenderer.Clear(); break; case DiscState.Recalled: TriggerRecallRoutine(); break; } }
void OnCollisionEnter(Collision collision) { // Only check for collisions as the server if (!isServer) { return; } //Debug.Log("Hit " + collision.gameObject.name); // Don't worry about collision if disc is held if (discState == DiscState.HELD) { return; } if (collision.gameObject.name == "Ground") { //Debug.Log("Hit ground at " + collision.GetContact(0).point + ", updating disc state to " + DiscState.GROUND); discState = DiscState.GROUND; } }
public void CmdMakeThrow(ThrowDistance throwDistance, ThrowCurve throwCurve, ThrowType throwType) { // Get indices for arrays from type of throw curveIndex = (int)throwCurve; int durationIndex = (int)throwDistance, heightIndex = (int)throwDistance, distanceIndex = (int)throwDistance; // Add forces useDiscBody(true); discBody.AddForce(transform.forward * distanceValues[distanceIndex]); discBody.AddForce(Vector3.up * heightValues[heightIndex]); // Spin the disc and make it fly discState = DiscState.FLIGHT; discBody.AddTorque(transform.up * rotationTorque); // Start routine for moving sideways curveEndTime = Time.time + durationValues[durationIndex]; curveDirection = transform.right; StartCoroutine("CurveRoutine"); // Start routine for detecting collisions StartCoroutine("CollisionsOnRoutine"); }
public void CmdPickup() { //Debug.Log("[SERVER] Request to update disc state received. Current state: " + discState); discState = DiscState.HELD; //Debug.Log("[SERVER] Disc state updated. Changed to: " + discState); }
/// <summary> /// initializes the flight of the disc based on power and direction /// TODO body rotation at the time of release for turn? /// </summary> public void BeginFlight(Disc disc, float throwPower, Vector3 throwDirection) { if (disc == this) { // set him free! // you're a free disc with endless possibilities!! transform.SetParent(null); // clamp throw power above 0.1f if (throwPower < 0.1f) { throwPower = 0.1f; } // set initial velocity velocity = (throwDirection * throwPower) + (throwDirection / 2); // it's flying _state = DiscState.InFlight; anim.SetTrigger("inFlight"); // de-subscribe for another throw UnsubscribeFromThrow(); // TEMP death countdown incase the disc goes through the terrain StartCoroutine(DeathCountdown(8f)); } }
/// <summary> /// raise the disc hit event, turn on rigidbody and halt animation /// </summary> /// <param name="goal"> did the disc hit a goal or a wall? </param> void RaiseDiscHit(bool goal, GameObject hit) { if (throwController != null) { return; } anim.Stop(); if (DiscHit != null) { DiscHit(this, hit); } if (state != DiscState.Dead) { if (!goal) { StartCoroutine(WaitForGravity(1f)); } else { this.enabled = false; } } _state = DiscState.Dead; }
/// <summary> /// subscribe to throwing event on throwControl /// </summary> public void SubscribeToThrow(ThrowController throwController) { _state = DiscState.InHand; this.throwController = throwController; throwController.ThrowDisc += BeginFlight; Reset(); }
public Disc(SerializationInfo info, StreamingContext unused) { num = info.GetInt32 ("num"); state = (DiscState)info.GetInt32 ("state"); }
public Disc(SerializationInfo info, StreamingContext unused) { num = info.GetInt32("num"); state = (DiscState)info.GetInt32("state"); }