Example #1
0
 private void Awake()
 {
     orbiting   = false;
     rb         = transform.root.GetComponent <Rigidbody2D>();
     hudScript  = FindObjectOfType <NavigationHUD>();
     gravScript = GetComponent <GravityApplier>();
 }
Example #2
0
    private void OnTriggerStay2D(Collider2D attracted)
    {
        //Check if attracted is already in trigger (happens if spawned in atmosphere)
        GravityApplier gravScript = attracted.GetComponent <GravityApplier>();

        if (attracted.CompareTag("Rocket"))
        {
            gravScript = attracted.transform.parent.GetComponent <GravityApplier>();
        }
        //TODO: find out why the planet gets added 2 times if building indicator hits player
        if (gravScript != null && !gravScript.planets.Contains(this))
        {
            gravScript.planets.Add(this);
        }

        //calculate and apply current drag to attracted based on its distance from the planet
        //GravityApplier gravScript = attracted.GetComponent<GravityApplier>();
        if (gravScript != null)
        {
            if (!gravScript.planets.Contains(this))
            {
                gravScript.planets.Add(this);
            }

            float scale           = transform.localScale.x;
            float distance        = Vector2.Distance(this.transform.position, attracted.transform.position);
            float attractedHeight = distance - hitbox.radius * scale;
            float t = attractedHeight / (gravityRadius.radius * scale - hitbox.radius * scale);
            //currentDrag = Mathf.Lerp(0, planetDrag, airResistanceCurve.Evaluate(t));

            gravScript.drag        = Mathf.Lerp(0, planetDrag, airResistanceCurve.Evaluate(t));
            gravScript.angularDrag = Mathf.Lerp(0, planetDrag / 2f, airResistanceCurve.Evaluate(t));
        }
    }
Example #3
0
 private void Awake()
 {
     rb               = transform.root.GetComponent <Rigidbody2D>();
     lineRenderer     = GetComponent <SpriteRenderer>();
     triangleRenderer = triangle.GetComponent <SpriteRenderer>();
     circleRenderer   = circle.GetComponent <SpriteRenderer>();
     gravScript       = target.GetComponent <GravityApplier>();
     selector         = transform.root.GetComponent <SelectorScript>();
 }
Example #4
0
    private void OnTriggerExit2D(Collider2D attracted)
    {
        //remove this planet from the list of attractors in attracted
        GravityApplier gravScript = attracted.GetComponent <GravityApplier>();

        if (gravScript != null)
        {
            gravScript.planets.Remove(this);
        }
    }
Example #5
0
    private void OnTriggerEnter2D(Collider2D attracted)
    {
        //add this planet to the list of attractors in attracted
        GravityApplier gravScript = attracted.GetComponent <GravityApplier>();

        //TODO: find out why the planet gets added 2 times if building indicator hits player
        if (gravScript != null && !gravScript.planets.Contains(this))
        {
            gravScript.planets.Add(this);
        }
    }