void Start() { if (gameControl.control.knowsDash == false) { dashState = DashState.Off; } else { dashState = DashState.Ready; } gameControl.control.maxhp = 50; gameControl.control.hp = 50; canv = GameObject.Find("Canvas").transform; rb = GetComponent <Rigidbody>(); canMove = true; slowTime = false; fakeGrav = GetComponent <ConstantForce>(); slowmobar = Instantiate(Resources.Load("ui/slowmo") as GameObject, canv).transform.GetChild(0).GetChild(0).transform.GetComponent <Image>(); if (gameControl.control.knowsDash) { slowmobar.gameObject.SetActive(true); } else { slowmobar.gameObject.SetActive(false); } }
private void InitializeVariables() { MovementChangeIterator = MovementChangeInterval; Heirarchy = Random.Range(1, 5); if (Heirarchy > 2) { isCarnivore = true; } tail.GetComponent <Renderer>().material.color = Color.Lerp(Color.green, Color.red, (Heirarchy / 5f)); body.GetComponent <Renderer>().material.color = Color.Lerp(Color.green, Color.red, (Heirarchy / 5f)); if (rb == null) { rb = gameObject.AddComponent <Rigidbody>(); } rb.useGravity = false; //rb.freezeRotation = true; if (constForce == null) { constForce = gameObject.AddComponent <ConstantForce>(); } initAge = Time.time; initScale = transform.localScale; InitialHungerReductionFactor = HungerReductionFactor; currentMovementDirection = new Vector3(Random.Range(0, 1.5f), Random.Range(0, 1.5f), Random.Range(0, 1.5f)); }
// Update is called once per frame void FixedUpdate() { ConstantForce force = GetComponent <ConstantForce>(); var velocity = new Vector3(0, 0, 0); if (transform.position.x < objectToChase.transform.position.x) { velocity += new Vector3(1, 0, 0); } else if (transform.position.x > objectToChase.transform.position.x) { velocity += new Vector3(-1, 0, 0); } if (transform.position.z < objectToChase.transform.position.z) { velocity += new Vector3(0, 0, 1); } else if (transform.position.z > objectToChase.transform.position.z) { velocity += new Vector3(0, 0, -1); } //if(Mathf.Abs(velocity.x) + Mathf.Abs(velocity.y) + Mathf.Abs(velocity.z) > 1) { // velocity = new Vector3(velocity.x / 2, velocity.y / 2, velocity.z / 2); //} //force.force = velocity; transform.rotation = Quaternion.AngleAxis(angle, velocity); angle += speed; if (angle > 360) { angle = 0; } }
public IEnumerator MaintainHeight() { ConstantForce cf = gameObject.GetComponent <ConstantForce>(); Rigidbody rb = gameObject.GetComponent <Rigidbody>(); while (toggled) { if (transform.position.y < desiredHeight - 1f) { upwardForce = 9.81f + correctionForce; if (rb.velocity.y > 0.01) { upwardForce = 9.81f; } } else if (transform.position.y > desiredHeight + 1f) { upwardForce = 9.81f - correctionForce; if (rb.velocity.y < -0.01f) { upwardForce = 9.81f; } } else { upwardForce = 9.81f; } cf.force = new Vector3(0f, upwardForce, 0f); yield return(new WaitForSeconds(0.25f)); } yield return(new WaitForSeconds(0f)); }
//bool ControlEnabled = true; // Start is called before the first frame update void Start() { rightBooster = GameObject.Find("SideBooster1"); leftBooster = GameObject.Find("SideBooster2"); body2 = GameObject.Find("Body2"); noseCone = GameObject.Find("NoseCone"); embers = GameObject.Find("FireEmbers (3)"); bigExplosion = GameObject.Find("BigExplosion"); currentSceneIndex = SceneManager.GetActiveScene().buildIndex; gameController = GameObject.Find("GameController"); Application.targetFrameRate = 120; if (currentSceneIndex > 0) { Cursor.visible = false; } else { Cursor.visible = true; } rocketRigidBody = GetComponent <Rigidbody>(); audioData = GetComponent <AudioSource>(); gameObject.GetComponent <Rigidbody>().useGravity = false; gravity = gameObject.AddComponent <ConstantForce>(); gravity.force = new Vector3(0.0f, -35f, 0.0f); }
private Gamelogic _logic; // Gamelogic component on Game Logic Game Object // Use this for initialization void Start() { // Get the ConstantForce component, Game Logic Game Object, and Gamelogic component _force = GetComponent <ConstantForce> () as ConstantForce; GAMELOGIC = GameObject.FindGameObjectWithTag("GAMELOGIC"); _logic = GAMELOGIC.GetComponent <Gamelogic> () as Gamelogic; }
private void ToggleRockets(bool state) { if (state) { haveRocketsFired = true; this.cf = this.gameObject.AddComponent <ConstantForce>(); this.cf.relativeForce = Vector3.up * 45f * rigid.mass; rocketsFiring = true; } else { this.cf.enabled = false; rocketsFiring = false; } foreach (ParticleSystem sys in Rockets) { var emis = sys.emission; emis.enabled = rocketsFiring; if (emis.enabled) { sys.Play(); } else { sys.Stop(); } } }
/// <summary> /// Creates an FFB effect, stores it at a given slot and starts its playback. /// </summary> /// <param name="data"> /// Parameters of the effect to be created. /// </param> /// <returns> /// Returns true if successful, otherwise returns false. /// </returns> public bool SendFFBEffect(DataClasses.FFBEffectData data) { //Check if the device is properly initialized if (ffbDevice == null) { MessageBox.Show("Device not initialized.", FFBInspector.Properties.Resources.errCap_devError, MessageBoxButtons.OK, MessageBoxIcon.Stop); return false; } //If there is an effect already stored in this slot, remove it StopOneEffect(data.slot); int[] axes = new Int32[actuatorsObjectTypes.Count]; int i = 0; foreach (int objt in actuatorsObjectTypes) { axes[i++] = objt; } //Set effect direction int[] dirs = data.effect.GetDirections(); //Set the general effect parameters up EffectParameters eParams = new EffectParameters(); eParams.Duration = data.effect.duration; eParams.Flags = EffectFlags.Cartesian | EffectFlags.ObjectIds; eParams.Gain = data.effect.gain; eParams.SetAxes(axes, dirs); eParams.StartDelay = data.effect.startDelay; eParams.SamplePeriod = 0; //Use the default sample period; eParams.TriggerButton = data.effect.trigButton; eParams.TriggerRepeatInterval = data.effect.trigRepInterval; //Set the type specific effect parameters up TypeSpecificParameters typeSpec = null; if (data.effect.effectGuid == EffectGuid.ConstantForce) { DataClasses.ConstantEffectTypeData cfEfd = (DataClasses.ConstantEffectTypeData)data.effect; typeSpec = new ConstantForce(); typeSpec.AsConstantForce().Magnitude = cfEfd.magnitude; } else if (data.effect.effectGuid == EffectGuid.RampForce) { DataClasses.RampEffectTypeData rfEfd = (DataClasses.RampEffectTypeData)data.effect; typeSpec = new RampForce(); typeSpec.AsRampForce().Start = rfEfd.start; typeSpec.AsRampForce().End = rfEfd.end; } else if (data.effect.effectGuid == EffectGuid.Sine || data.effect.effectGuid == EffectGuid.Triangle || data.effect.effectGuid == EffectGuid.Square || data.effect.effectGuid == EffectGuid.SawtoothUp || data.effect.effectGuid == EffectGuid.SawtoothDown) { DataClasses.PeriodicEffectTypeData pfEfd = (DataClasses.PeriodicEffectTypeData)data.effect; typeSpec = new PeriodicForce(); typeSpec.AsPeriodicForce().Magnitude = pfEfd.magnitude; typeSpec.AsPeriodicForce().Offset = pfEfd.offset; typeSpec.AsPeriodicForce().Period = pfEfd.period; typeSpec.AsPeriodicForce().Phase = pfEfd.phase; } else if (data.effect.effectGuid == EffectGuid.Friction || data.effect.effectGuid == EffectGuid.Inertia || data.effect.effectGuid == EffectGuid.Damper || data.effect.effectGuid == EffectGuid.Spring) { DataClasses.ConditionEffectTypeData cdEfd = (DataClasses.ConditionEffectTypeData)data.effect; typeSpec = new ConditionSet(); typeSpec.AsConditionSet().Conditions = new Condition[1]; typeSpec.AsConditionSet().Conditions[0].DeadBand = cdEfd.deadBand; typeSpec.AsConditionSet().Conditions[0].Offset = cdEfd.offset; typeSpec.AsConditionSet().Conditions[0].NegativeCoefficient = cdEfd.negCoeff; typeSpec.AsConditionSet().Conditions[0].NegativeSaturation = cdEfd.negSat; typeSpec.AsConditionSet().Conditions[0].PositiveCoefficient = cdEfd.posCoeff; typeSpec.AsConditionSet().Conditions[0].PositiveSaturation = cdEfd.posSat; } eParams.Parameters = typeSpec; //Create an envelope if (data.envelope != null) { Envelope envp = new Envelope(); envp.AttackLevel = data.envelope.attackLevel; envp.AttackTime = data.envelope.attackTime; envp.FadeLevel = data.envelope.fadeLevel; envp.FadeTime = data.envelope.fadeTime; eParams.Envelope = envp; } //Create an effect and add it to the list Effect ef; try { ef = new Effect(ffbDevice, data.effect.effectGuid, eParams); ffbEffects[data.slot] = ef; } catch (Exception ex) { MessageBox.Show("Cannot create effect.\n" + ex.Message + "\n" + ex.Data, FFBInspector.Properties.Resources.errCap_effError, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return StartFFBEffect(ef); }