private void Start() { if (lifeTime == 0) { lifeTime = 10f; } Destroy(gameObject, lifeTime); rb = GetComponent <Rigidbody>(); thrower = FindObjectOfType <Throwing>(); gravity = thrower.Gravity; time = 0f; initialVelocity = thrower.InitialThrowingVelocity; // convert deg to rad alpha = thrower.TurningAngle * Mathf.PI / 180f; beta = (90 - thrower.TurningAngle) * Mathf.PI / 180f; theta = thrower.Theta; cosAlpha = Mathf.Cos(alpha); cosBeta = Mathf.Cos(beta); cosTheta = Mathf.Cos(theta); sinTheta = Mathf.Sin(theta); initialVelocityX = initialVelocity * cosTheta * cosBeta; initialVelocityY = initialVelocity * sinTheta; initialVelocityZ = initialVelocity * cosTheta * cosAlpha; }
//respawn object, or destroy it and create the SpawnOnDeath objects void Death() { //player drop item if(tag == "Player") throwing = GetComponent<Throwing>(); if(throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") throwing.ThrowPickup(); if (deadSound) //AudioSource.PlayClipAtPoint(deadSound, transform.position); flashing = false; flashObject.GetComponent<Renderer>().material.color = originalColor; if(respawn) { if(GetComponent<Rigidbody>()) GetComponent<Rigidbody>().velocity *= 0; transform.position = respawnPos; dead = false; currentHealth = defHealth; } else Destroy (gameObject); if (spawnOnDeath.Length != 0) foreach(GameObject obj in spawnOnDeath) Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); }
//respawn object, or destroy it and create the SpawnOnDeath objects public virtual void Death() { if (respawn) { currentHealth = defHealth; dead = false; Rigidbody rigid = GetComponent <Rigidbody>(); currentHealth = defHealth; InstantRespawn = false; rigid.isKinematic = false; if (this.gameObject.tag == "Player") { AnimatorControl.SetBool("KO", false); } //rigid.velocity *= 0; transform.position = respawnPos; //Original spawn location upon initilization(Start of scene). rigid.velocity *= 0; if (rigid) { rigid.isKinematic = false; rigid.velocity *= 0; } } else { Destroy(gameObject); //Q Consider Object pooling. } //player drop item if (tag == "Player") { // Q - Get Animator Controller AnimatorControl = GetComponent <Throwing>().animator; throwing = GetComponent <Throwing>(); if (throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") { throwing.ThrowPickup(); } RespawnPlayer(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; //Respawn GameObject if (spawnOnDeath.Length != 0) { foreach (GameObject obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } } }
public static void SpawnPlayer(GameObject player, Vector3 location) { Throwing throwing = player.GetComponent <Throwing>(); Health health = player.GetComponent <Health>(); throwing.ammo = throwing.maxAmmo; health.BeInvincible(respawnInvincibilityTime); player.transform.position = location; }
void Start() { bimpactclip = Resources.Load <AudioClip>("Audio/BadImpact"); goodclip = Resources.Load <AudioClip>("Audio/GhostHit"); badimpact = Addsound.AddAudio(bimpactclip, false, 1f, GameObject.FindGameObjectWithTag("Player")); goodimpact = Addsound.AddAudio(goodclip, false, 1f, GameObject.FindGameObjectWithTag("Player")); throwclass = FindObjectOfType <Throwing>(); rb = GetComponent <Rigidbody2D>(); rb.velocity = transform.right * speed; }
//respawn object, or destroy it and create the SpawnOnDeath objects void Death() { //player drop item if (tag == "Player") { throwing = GetComponent <Throwing>(); } if (throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") { throwing.ThrowPickup(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; if (respawn) { Rigidbody rigid = GetComponent <Rigidbody> (); if (rigid) { rigid.velocity *= 0; } transform.position = respawnPos; dead = false; currentHealth = defHealth; } else { if (gameObject.tag != "Enemy") { bonus.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z); Instantiate(bonus); } Destroy(gameObject); } if (spawnOnDeath.Length != 0) { foreach (GameObject obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } } }
/** Configures and syncs properties required on a state change */ void SyncState() { if (WorldState.ball != currentState) { currentState = WorldState.ball; switch (currentState) { case BallState.Air: var velocity = Mathf.Max((transform.position - target.position).magnitude, 20); steering = new Steering(); steering.velocity = Throwing.Velocity(transform.position, target.position + new Vector3(0, BallController.floorHeight, 0), velocity, gravity); break; } } }
private void OnTriggerEnter(Collider other) { Throwing ball = other.GetComponent <Throwing>(); if (ball != null) { Destroy(ball); if (_ballNumber != _maxballs) { Invoke("SpawnBall", _timeTillNextBall); } else { Invoke("EndGame", _timeTillNextBall); } } }
void Update() { if (Input.GetKeyDown(KeyCode.Space) && _bowlingBall != null) { _bowlingBall.Throw(); _bowlingBall = null; _ballsThrown++; } HitPins(); if (_isBowling) { _camera.transform.position = Vector3.Lerp(_camera.transform.position, _bowlingPov.position, 10 * Time.deltaTime); _camera.transform.rotation = Quaternion.Lerp(_camera.transform.rotation, _bowlingPov.rotation, 10 * Time.deltaTime); } }
// Start is called before the first frame update void Start() { _throwing = GetComponent <Throwing>(); if (!_throwing) { return; } Coroutine coroutine = null; GetComponentInChildren <Detector>().onDetect += detected => coroutine = StartCoroutine(DoThrowing(detected.transform)); GetComponentInChildren <Detector>().onOutOfSight += detected => StopCoroutine(coroutine); }
//setup public virtual void Awake() { aSource = GetComponent <AudioSource>(); if (currentHealth <= 0) { Debug.LogWarning(transform.name + " has 'currentHealth' set to 0 or less in 'Health' script: it has been destroyed upon scene start"); } aSource.playOnAwake = false; if (flashObject == null) { flashObject = transform; } flashRender = flashObject.GetComponent <Renderer>(); if (flashRender) { originalColor = flashRender.material.color; } defHealth = currentHealth; respawnPos = transform.position; if (gameObject.CompareTag("Player")) { int a = 5 + 4; } //Get reference to controller if (tag == "Player") { //Q - Get Animator Controller AnimatorControl = GetComponent <Throwing> ().animator; throwing = GetComponent <Throwing> (); } AnimatorControl = GetComponentInChildren <Animator>(); myRigidbody = GetComponent <Rigidbody> (); }
void Awake() { throwclass = GameObject.FindObjectOfType <Throwing>(); }
private void UpdateUnityInput() { UpdateTrackedControllers(); // Motion foreach (uint id in devices.Keys) { var nodeType = id.GetNodeType(); var position = InputTracking.GetLocalPosition(nodeType); var rotation = InputTracking.GetLocalRotation(nodeType); XRNodeState nodeState; if (Throwing.TryGetNodeState(nodeType, out nodeState)) { Vector3 controllerVelocity; nodeState.TryGetVelocity(out controllerVelocity); LastVelocity[id] = controllerVelocity; LastPositions[id] = position; } SetTransform(devices[id], position, rotation); } if (CanThrow) { // Create new if (Input.GetButtonDown("MotionController-Select-Left")) { this.CreateNew(NodeExtensions.LEFT_ID); } if (Input.GetButtonDown("MotionController-Select-Right")) { this.CreateNew(NodeExtensions.RIGHT_ID); } if (Input.GetAxis("MotionController-GraspedAmmount-Left") > GripSensitivity && lastGripLeft <= GripSensitivity) { this.CreateNew(NodeExtensions.LEFT_ID); } if (Input.GetAxis("MotionController-GraspedAmmount-Right") > GripSensitivity && lastGripRight <= GripSensitivity) { this.CreateNew(NodeExtensions.RIGHT_ID); } } // Swap if (Input.GetButtonDown("MotionController-Menu-Left")) { this.TrySwitchHeldObject(NodeExtensions.LEFT_ID); } if (Input.GetButtonDown("MotionController-Menu-Right")) { this.TrySwitchHeldObject(NodeExtensions.RIGHT_ID); } if (Input.GetButtonDown("MotionController-TouchpadPressed-Left")) { this.TrySwitchHeldObject(NodeExtensions.LEFT_ID); } if (Input.GetButtonDown("MotionController-TouchpadPressed-Right")) { this.TrySwitchHeldObject(NodeExtensions.RIGHT_ID); } if (CanThrow) { // Throw if (Input.GetButtonUp("MotionController-Select-Left")) { this.TryThrow(XRNode.LeftHand); } if (Input.GetButtonUp("MotionController-Select-Right")) { this.TryThrow(XRNode.RightHand); } if (Input.GetAxis("MotionController-GraspedAmmount-Left") <= GripSensitivity && lastGripLeft > GripSensitivity) { this.TryThrow(XRNode.LeftHand); } if (Input.GetAxis("MotionController-GraspedAmmount-Right") <= GripSensitivity && lastGripRight > GripSensitivity) { this.TryThrow(XRNode.RightHand); } } lastGripLeft = Input.GetAxis("MotionController-GraspedAmmount-Left"); lastGripRight = Input.GetAxis("MotionController-GraspedAmmount-Right"); }
protected override void WriteXml(XmlWriter writer) { writer.WriteAttributeString("Name", Name); writer.WriteStartAttribute("Offset"); writer.WriteValue(Offset); writer.WriteEndAttribute(); writer.WriteValueElement(Strings.JPCost, JPCost); writer.WriteValueElement(Strings.LearnRate, LearnRate); writer.WriteValueElement(Strings.AbilityType, AbilityType); writer.WriteValueElement(Strings.LearnWithJP, LearnWithJP); writer.WriteValueElement(Strings.Action, Action); writer.WriteValueElement(Strings.LearnOnHit, LearnOnHit); writer.WriteValueElement(Strings.Blank1, Blank1); writer.WriteValueElement(Strings.Unknown1, Unknown1); writer.WriteValueElement(Strings.Unknown2, Unknown2); writer.WriteValueElement(Strings.Unknown3, Unknown3); writer.WriteValueElement(Strings.Blank2, Blank2); writer.WriteValueElement(Strings.Blank3, Blank3); writer.WriteValueElement(Strings.Blank4, Blank4); writer.WriteValueElement(Strings.Blank5, Blank5); writer.WriteValueElement(Strings.Unknown4, Unknown4); writer.WriteStartElement("AI"); ((IXmlSerializable)AIFlags).WriteXml(writer); writer.WriteEndElement(); if (Effect != null) { writer.WriteStartElement("Effect"); writer.WriteStartAttribute("value"); writer.WriteValue(Effect.Value); writer.WriteEndAttribute(); writer.WriteAttributeString("name", Effect.Name); } if (IsNormal) { writer.WriteStartElement("Attributes"); ((IXmlSerializable)Attributes).WriteXml(writer); writer.WriteEndElement(); } else if (IsItem) { writer.WriteStartElement("ItemOffset"); writer.WriteValue(ItemOffset); } else if (IsThrowing) { writer.WriteStartElement("Throwing"); writer.WriteValue(Throwing.ToString()); } else if (IsJumping) { writer.WriteStartElement("Jumping"); writer.WriteValueElement("JumpHorizontal", JumpHorizontal); writer.WriteValueElement("JumpVertical", JumpVertical); } else if (IsCharging) { writer.WriteStartElement("Charging"); writer.WriteValueElement("ChargeCT", ChargeCT); writer.WriteValueElement("ChargeBonus", ChargeBonus); } else if (IsArithmetick) { writer.WriteStartElement("ArithmetickSkill"); writer.WriteValue(ArithmetickSkill); } else if (IsOther) { writer.WriteStartElement("OtherID"); writer.WriteValue(OtherID); } else { throw new InvalidOperationException("Invalid item type"); } writer.WriteEndElement(); }
// Use this for initialization void Start() { throwingClassOnPlayer = transform.parent.GetComponent<Throwing>(); }
private void SpawnBall() { _bowlingBall = Instantiate(_throwing, _spawnPosition, transform.rotation); _ballNumber++; }
// Use this for initialization void Start () { throwScript = GetComponent<Throwing>(); }