private void Awake() { planet = GameObject.Find("Planet").GetComponent <PlanetGravity>(); rb = this.GetComponent <Rigidbody>(); rb.useGravity = false; rb.constraints = RigidbodyConstraints.FreezeRotation; }
void Awake() { planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <PlanetGravity>(); rigidbodyObject = GetComponent <Rigidbody>(); // Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script rigidbodyObject.useGravity = false; rigidbodyObject.constraints = RigidbodyConstraints.FreezeRotation; }
// Start is called before the first frame update void Start() { planet = GetComponentInParent <PlanetGravity>(); anim = GetComponentInParent <Animator>(); sprite = GetComponent <SpriteRenderer>(); idleColor = sprite.color; instancedMaterial = sprite.material; UpdateAreaSize(); }
//void UpdatePlanetPreview() //{ // if(Input.GetMouseButtonDown(0)) // { // worldMouseButtonDownPosition = CursorPosition.worldPosition; // planetPreview.transform.position = worldMouseButtonDownPosition; // planetPreview.radius = 0; // } // if (Input.GetMouseButton(0)) // { // planetPreview.gameObject.SetActive(true); // planetPreview.radius = Mathf.SmoothDamp(planetPreview.radius, ComputePlanetRadius(true, true), ref refSize, previewSmooth); // } // else // { // planetPreview.gameObject.SetActive(false); // } //} void SpawnPlanet() { PlanetGravity planet = Instantiate(planetPrefab, worldMouseButtonDownPosition, Quaternion.identity, transform); planet.radius = ComputePlanetRadius(true, true); float relativeRadius = (planet.radius - minPlanetRadius) / (maxPlanetRadius - minPlanetRadius); planet.mass = Mathf.Lerp(minGravity, maxGravity, relativeRadius); }
// Use this for initialization void Start() { player = GameObject.Find("Spaceman"); playerInput = player.GetComponent <TouchInput>(); planet = GameObject.Find("Cloudus 456"); planetScript = planet.GetComponent <PlanetGravity>(); }
void Start() { planetPlayerIsOn = GameObject.FindGameObjectWithTag("Planet").GetComponent <PlanetGravity>(); rigidbody = GetComponent <Rigidbody>(); rigidbody.useGravity = false; rigidbody.constraints = RigidbodyConstraints.FreezeRotation; }
// Use this for initialization void Start() { rigidbody2d = GetComponent <Rigidbody2D>(); sprite = transform.Find("SpriteContainer"); anim = sprite.Find("Sprite").GetComponent <Animator>(); spriteRenderer = sprite.Find("Sprite").GetComponent <SpriteRenderer>(); pg = GetComponent <PlanetGravity>(); audioSource = GetComponent <AudioSource>(); }
// Start is called before the first frame update protected void Awake() { //Find the rigidbody attached to this object objectRB = GetComponent <Rigidbody>(); //If we don't have a planet then find the closet one and assign it if (planet == null) { planet = FindClosestPlanet(); } }
// Start is called before the first frame update void Start() { planet = FindObjectOfType <PlanetGravity>(); rb = GetComponent <Rigidbody>(); roverTransform = FindObjectOfType <RoverController>().transform; healthBar.maxValue = health; healthBar.value = health; FindNewWaypoint(); GetComponent <AudioSource>().volume *= AppManager.instance.fxVolume; noiseDelay = Random.Range(6f, 20f); }
// Start is called before the first frame update void Start() { planet = GetComponent <PlanetGravity>(); instancedMaterial = GetComponent <SpriteRenderer>().material; anim = GetComponent <Animator>(); baseFrequency = instancedMaterial.GetFloat("_NoiseFreq"); if (randomizeAtStart) { SetPlanetColors(); SetPlanetNoise(); } UpdatePlanetSize(); }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Planet") { currentPlanet = coll.gameObject; PlanetGravity pg = new PlanetGravity(); pg.SetCurrentPlanet(currentPlanet.transform); isMoving = false; HingeJoint2D joint = transform.GetComponent <HingeJoint2D>(); if (!joint.enabled) { joint.connectedBody = currentPlanet.transform.GetComponent <Rigidbody2D>(); Vector2 anchor = new Vector2(coll.contacts[0].point.x, coll.contacts[0].point.y);; joint.connectedAnchor = currentPlanet.transform.InverseTransformPoint(anchor); transform.up = coll.contacts[0].normal; joint.enabled = true; Transform range = currentPlanet.transform.FindChild("GravityRange"); if (range != null) { PlanetGravity gravity = range.GetComponent <PlanetGravity>(); if (gravity != null) { if (!gravity.isVisited) { score++; gravity.isVisited = true; } } } } if (currentPlanet.name.Equals("final")) { GameManager.UpdateScoreOnWin(score); Application.LoadLevel("NextLevelChange"); } if (currentPlanet.name.Equals("finall")) { GameManager.UpdateScoreOnWin(score); Application.LoadLevel("GameOver"); } if (currentPlanet.name.Equals("Blackhole")) { Application.LoadLevel("LevelChange"); } } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Planet") { currentPlanet = coll.gameObject; PlanetGravity pg = new PlanetGravity(); pg.SetCurrentPlanet(currentPlanet.transform); isMoving = false; HingeJoint2D joint = transform.GetComponent<HingeJoint2D>(); if(!joint.enabled) { joint.connectedBody = currentPlanet.transform.GetComponent<Rigidbody2D>(); Vector2 anchor = new Vector2(coll.contacts[0].point.x,coll.contacts[0].point.y);; joint.connectedAnchor = currentPlanet.transform.InverseTransformPoint(anchor); transform.up = coll.contacts[0].normal; joint.enabled = true; Transform range = currentPlanet.transform.FindChild("GravityRange"); if(range != null) { PlanetGravity gravity = range.GetComponent<PlanetGravity>(); if(gravity != null) if(!gravity.isVisited) { score++; gravity.isVisited = true; } } } if(currentPlanet.name.Equals("final")) { GameManager.UpdateScoreOnWin(score); Application.LoadLevel("NextLevelChange"); } if(currentPlanet.name.Equals("finall")) { GameManager.UpdateScoreOnWin(score); Application.LoadLevel("GameOver"); } if(currentPlanet.name.Equals("Blackhole")) { Application.LoadLevel("LevelChange"); } } }
void Start() { audio = GetComponent <AudioSource>(); PlanetGravity planet = GetComponent <PlanetGravity>(); audio.minDistance = planet.radius; audio.maxDistance = planet.gravityRadius + 3; //Delay the start on frame to let the other components initialize Invoke("SetUpAmbienceSound", 0.01f); StartCoroutine(LerpVolumeIn()); //Play the chord sound soundId = planetSoundCount; planetSoundCount++; AudioManager.Instance.PlayChord(soundId); }
Vector3[] ComputePreviewPoints() { Vector2 position = rigidbody.position; Vector2 velocity = rigidbody.velocity; Vector3[] points = new Vector3[pointCount + 1]; float elapsedTime = 0; points[0] = position; while (elapsedTime < previewTime) { //Update the velocity List <PlanetGravity> planets = PlanetGravity.GetAllPlanetsApplyingGravity(position); foreach (PlanetGravity planet in planets) { planet.AngleGravityPull(position, ref velocity, out float torque); } if (PlanetSpawner.Instance.planetPreview.PositionIsInGravityArea(position)) { Vector2 previewPosition = PlanetSpawner.Instance.planetPreview.transform.position; float previewMass = PlanetSpawner.Instance.planetPreview.mass; PlanetGravity.EmulatePlanetGravity(previewPosition, previewMass, position, ref velocity, out bool isBoosting, out float torque); } velocity = velocity * (1 - Time.fixedDeltaTime * rigidbody.drag); //max velocity if (velocity.magnitude > Physics2D.maxTranslationSpeed / Time.fixedDeltaTime) { velocity = velocity.normalized * Physics2D.maxTranslationSpeed / Time.fixedDeltaTime; } position += velocity * Time.fixedDeltaTime; int currentId = Mathf.CeilToInt((elapsedTime / previewTime) * pointCount); points[currentId] = position; elapsedTime += Time.fixedDeltaTime; } return(points); }
/// <summary> /// Find the closest planet /// </summary> /// <returns>The closest planet</returns> private PlanetGravity FindClosestPlanet() { //Store the closest planet and distance float closestDist = Mathf.Infinity; PlanetGravity closestPlanet = null; //Get all of the planet scripts PlanetGravity[] allPlanets = FindObjectsOfType <PlanetGravity>(); foreach (PlanetGravity planet in allPlanets) { //If the distance to this planet is less than the current distnace then //set the new closest if (Vector3.Distance(planet.gameObject.transform.position, transform.position) < closestDist) { closestPlanet = planet; closestDist = Vector3.Distance(planet.gameObject.transform.position, transform.position); } } //Return the closest planet - this will be null if there are no planets return(closestPlanet); }
void IConvertGameObjectToEntity.Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var component = new PlanetGravity() { GravitationalCenter = transform.position, GravitationalMass = GravitationalMass, GravitationalConstant = GravitationalConstant, EventHorizonDistance = EventHorizonDistance, RotationMultiplier = RotationMultiplier }; dstManager.AddComponentData(entity, component); if (dstManager.HasComponent <PhysicsMass>(entity)) { var bodyMass = dstManager.GetComponentData <PhysicsMass>(entity); Random random = new Random(); random.InitState(10); bodyMass.InverseMass = random.NextFloat(bodyMass.InverseMass, bodyMass.InverseMass * 4f); dstManager.SetComponentData(entity, bodyMass); } }
private void Start() { pg = GetComponent <PlanetGravity>(); }
private void Awake() { planetGravity = GameObject.FindGameObjectWithTag("Planet").GetComponent <PlanetGravity>(); GetComponent <Rigidbody>().useGravity = false; GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; }
void Start() { pScript = GameObject.FindGameObjectWithTag("Planet").GetComponent <PlanetGravity>(); }
// Use this for initialization void Start() { pg = GetComponent <PlanetGravity>(); rigidbody2d = GetComponent <Rigidbody2D>(); }
// Start is called before the first frame update void Start() { planet = GetComponent <PlanetGravity>(); gravityRendering = GetComponentInChildren <GravityAreaRendering>(); }
public void GetPlanet() { planetScript = GameObject.Find("Planet").GetComponent <PlanetGravity>(); }
// Use this for initialization void Start() { pg = plumber.GetComponent <PlanetGravity>(); }