TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController) { TriggerState rightTriggerState = rightController.GetTriggerState(); Vector2 rightTouchpadAxis = rightController.GetTouchpadAxis(); Vector3 rightControllerPosition = rightController.GetPosition(); Vector3 rightControllerDirection = rightController.GetDirection(); Vector3 rightControllerVelocity = rightController.GetVelocity(); TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null; Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero; Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?; Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?; Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?; if (rightTriggerState.down) { // check if wand is visible in the camera view Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera); Bounds wandBounds = new Bounds(rightControllerPosition, new Vector3(0.1f, 0.1f, 0.1f)); if (!GeometryUtility.TestPlanesAABB(planes, wandBounds)) { potion = GameObject.Instantiate(potionPrefab, rightControllerPosition, new Quaternion(0f, 0f, 0f, 0f)) as GameObject; } else { potion = null; } } else if (rightTriggerState.press && potion != null) { potion.transform.position = rightControllerPosition + (rightControllerDirection * 0.1f); lastWandPosition = rightControllerPosition; } else if (rightTriggerState.up && potion != null) { Rigidbody potionRigibody = potion.gameObject.GetComponent <Rigidbody> (); // TODO Das hier verwendet die Geschwindigkeit der Hand, nicht der Potion (die ja vor der Hand schwebt). // Wäre es nicht intuitiver, hier die Potion-Positionen zu verwenden? // Außerdem könnte man dann schön aus dem Handgelenk werfen. :) potionRigibody.velocity = Time.deltaTime * (rightControllerPosition - lastWandPosition) * 18000f; potionRigibody.constraints = RigidbodyConstraints.None; float torqueMultiplier = 100f; potionRigibody.AddTorque( UnityEngine.Random.Range(-torqueMultiplier, torqueMultiplier), UnityEngine.Random.Range(-torqueMultiplier, torqueMultiplier), UnityEngine.Random.Range(-torqueMultiplier, torqueMultiplier) * 100f); } TWandAction[] actions = { }; return(actions); }
TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController) { TriggerState rightTriggerState = rightController.GetTriggerState(); Vector2 rightTouchpadAxis = rightController.GetTouchpadAxis(); Vector3 rightControllerPosition = rightController.GetPosition(); Vector3 rightControllerDirection = rightController.GetDirection(); Vector3 rightControllerVelocity = rightController.GetVelocity(); TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null; Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero; Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?; Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?; Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?; UpdateControllerStateAndTrap(rightTriggerState, rightTouchpadAxis, rightControllerPosition, rightControllerDirection, ref rightHandTrapSource, ref rightHandPlacedTrapSource, ref rightHandState, ref rightHandThrowingStartPosition, ref rightHandThrowingStartTime, ref rightHandThrowVelocity, ref rightHandThrowPosition, ref rightHandThrowTime ); UpdateControllerStateAndTrap(leftTriggerState, leftTouchpadAxis, leftControllerPosition, leftControllerDirection, ref leftHandTrapSource, ref leftHandPlacedTrapSource, ref leftHandState, ref leftHandThrowingStartPosition, ref leftHandThrowingStartTime, ref leftHandThrowVelocity, ref leftHandThrowPosition, ref leftHandThrowTime ); // when both are placed, finish and reset if (rightHandState == ControllerAndTrapSourceState.Arrived && leftHandState == ControllerAndTrapSourceState.Arrived) { MakeTrapSolid(rightHandPlacedTrapSource); MakeTrapSolid(leftHandPlacedTrapSource); GameObject laser = CreateLaser(rightHandPlacedTrapSource.transform.position, leftHandPlacedTrapSource.transform.position); Object.Destroy(rightHandTrapSource); Object.Destroy(leftHandTrapSource); Object.Destroy(rightHandPlacedTrapSource, lifetime); Object.Destroy(leftHandPlacedTrapSource, lifetime); Object.Destroy(laser, lifetime); Init(); } TWandAction[] actions = { }; return(actions); }
TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController) { TriggerState rightTriggerState = rightController.GetTriggerState(); Vector2 rightTouchpadAxis = rightController.GetTouchpadAxis(); Vector3 rightControllerPosition = rightController.GetPosition(); Vector3 rightControllerDirection = rightController.GetDirection(); Vector3 rightControllerVelocity = rightController.GetVelocity(); TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null; Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero; Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?; Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?; Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?; UpdateSpellSelectState(rightTriggerState, leftTriggerState); switch (spellSelectState) { case SpellSelectState.Aiming: if (rightTriggerState.press) { UpdateAiming(rightControllerPosition, rightControllerDirection); } if (this.previewSphere && rightTriggerState.up) { spellSelectState = SpellSelectState.MeteorSpawned; meteorToDragScript = SpawnMeteorToPosition(previewSphere.transform.position).GetComponent <MeteorController>(); } break; case SpellSelectState.MeteorSpawned: if (rightTriggerState.press && leftTriggerState.press) { spellSelectState = SpellSelectState.Dragging; meteorToDragScript.SetTargetArea(previewSphere.transform.position); UnityEngine.Object.Destroy(this.previewSphere); //TODO check ob linker controller ueberhaupt da ist draggingStartPosition = (rightControllerPosition.y + leftControllerPosition.Value.y) / 2f; } break; case SpellSelectState.Dragging: if (!rightTriggerState.press && !leftTriggerState.press) { float draggingEndPosition = (rightControllerPosition.y + leftControllerPosition.Value.y) / 2f; float dragLength = Mathf.Max(draggingStartPosition - draggingEndPosition, 0f); spellSelectState = SpellSelectState.Aiming; if (dragLength <= 0.1f) { meteorToDragScript.DestroyMeteor(); } else { meteorToDragScript.SetSpeed(dragLength * 25f); meteorToDragScript.StartFalling(); } } break; } TWandAction[] actions = { }; return(actions); }
TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController) { TriggerState rightTriggerState = rightController.GetTriggerState(); Vector2 rightTouchpadAxis = rightController.GetTouchpadAxis(); Vector3 rightControllerPosition = rightController.GetPosition(); Vector3 rightControllerDirection = rightController.GetDirection(); Vector3 rightControllerVelocity = rightController.GetVelocity(); TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null; Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero; Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?; Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?; Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?; switch (spellSelectState) { case SpellSelectState.Spawning: if (rightTriggerState.down) { Vector3 position = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection); this.lightningObject = GameObject.Instantiate(this.lightningPrefab, new Vector3(0, 0, 0), new Quaternion()); Transform transformTemp = this.lightningObject.transform; this.lightningStart = transformTemp.GetChild(0).transform; this.lightningMitte = transformTemp.GetChild(1).transform; this.lightningTarget = transformTemp.GetChild(2).transform; this.lightningMitte.position = position; this.middlePointParticlesystem = this.lightningObject.GetComponentInChildren <ParticleSystem> (); this.middlePointParticlesystem.Play(); this.lightningObject.GetComponent <LineRenderer> ().enabled = false; spellSelectState = SpellSelectState.Grabbing; } break; case SpellSelectState.Grabbing: if (rightTriggerState.press) { this.lightningMitte.position = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection); } else { CancelSpell(); } if (rightTriggerState.up) { CancelSpell(); break; } if (leftTriggerState.down) { spellSelectState = SpellSelectState.Dragging; } break; case SpellSelectState.Dragging: Vector3?target = FindTarget(this.lightningMitte.position, (Vector3)leftControllerPosition - rightControllerPosition); if (target != null) { this.lightningTarget.position = (Vector3)target; this.lightningStart.position = rightControllerPosition; this.lightningMitte.position = rightControllerPosition + ((rightControllerPosition - this.playerEyesTransform.position).magnitude * 30f * rightControllerDirection); this.middlePointParticlesystem.Stop(); this.lightningObject.GetComponent <LineRenderer> ().enabled = true; } else { CancelSpell(); } if (rightTriggerState.up || leftTriggerState.up) { CancelSpell(); } break; } TWandAction[] actions = { }; return(actions); }
TWandAction[] Spell.UpdateSpell(ControllerBridge rightController, ControllerBridge leftController) { TriggerState rightTriggerState = rightController.GetTriggerState(); Vector2 rightTouchpadAxis = rightController.GetTouchpadAxis(); Vector3 rightControllerPosition = rightController.GetPosition(); Vector3 rightControllerDirection = rightController.GetDirection(); Vector3 rightControllerVelocity = rightController.GetVelocity(); TriggerState leftTriggerState = leftController != null?leftController.GetTriggerState() : null; Vector2 leftTouchpadAxis = leftController != null?leftController.GetTouchpadAxis() : Vector2.zero; Vector3?leftControllerPosition = leftController != null?leftController.GetPosition() : null as Vector3?; Vector3?leftControllerDirection = leftController != null?leftController.GetDirection() : null as Vector3?; Vector3?leftControllerVelocity = leftController != null?leftController.GetVelocity() : null as Vector3?; switch (spellSelectState) { case SpellSelectState.Aiming: if (rightTriggerState.down) { Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection); if (target != null) { this.lightningObject = GameObject.Instantiate(this.lightningPrefab, rightControllerPosition - new Vector3(-10, -10, -10), new Quaternion()); Transform transformTemp = this.lightningObject.transform; this.lightningStart = transformTemp.GetChild(0).transform; this.lightningMitte = transformTemp.GetChild(1).transform; this.lightningTarget = transformTemp.GetChild(2).transform; this.lightningStart.position = rightControllerPosition; this.lightningTarget.position = (Vector3)target; this.lightningMitte.position = (this.lightningStart.position + this.lightningTarget.position) / 2; spellSelectState = SpellSelectState.Grabbing; } } break; case SpellSelectState.Grabbing: if (rightTriggerState.press) { Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection); if (target != null) { this.lightningStart.position = rightControllerPosition; this.lightningTarget.position = (Vector3)target; this.lightningMitte.position = (this.lightningStart.position + this.lightningTarget.position) / 2; } else { CancelSpell(); } } else { CancelSpell(); } if (leftTriggerState.down) { this.bendingStartPosition = (Vector3)leftControllerPosition; this.middleBeforeBending = this.lightningMitte.position; spellSelectState = SpellSelectState.Bending; } break; case SpellSelectState.Bending: if (leftTriggerState.up) { spellSelectState = SpellSelectState.Grabbing; break; } if (rightTriggerState.press) { Vector3?target = FindTarget(rightControllerPosition, rightControllerDirection); if (target != null) { this.lightningStart.position = rightControllerPosition; this.lightningTarget.position = (Vector3)target; this.lightningMitte.position = (this.lightningStart.position + this.lightningTarget.position) / 2; this.middleBeforeBending = this.lightningMitte.position; } else { CancelSpell(); } } else { CancelSpell(); } if (leftTriggerState.down) { this.bendingStartPosition = (Vector3)leftControllerPosition; } Vector3 offset = (Vector3)(this.bendingStartPosition - leftControllerPosition) * 20; this.lightningMitte.position = this.middleBeforeBending + offset; break; // TODO spark effekt wenn man kein ziel getroffen hat } TWandAction[] actions = { }; return(actions); }