// Update is called once per frame void Update() { if (isRunning) { Rigidbody2D body = player.GetComponent <Rigidbody2D>(); float mass = body.mass; foreach (GameObject attractor in attractors) { Vector2 dir = attractor.GetComponent <GravitySource>().GetGravityForce(player.transform.position, mass); body.AddForce(dir, ForceMode2D.Force); ForceArrow arrow = forceArrows[attractor.GetInstanceID()].GetComponent <ForceArrow>(); arrow.force = dir / 5; // Vector3 dir3 = new Vector3 ( dir.x, dir.y ); } foreach (GameObject repeller in repellers) { Vector2 dir = repeller.GetComponent <GravitySource>().GetGravityForce(player.transform.position, mass); body.AddForce(dir, ForceMode2D.Force); ForceArrow arrow = forceArrows[repeller.GetInstanceID()].GetComponent <ForceArrow>(); arrow.force = dir / 5; // Vector3 dir3 = new Vector3 ( dir.x, dir.y ); } } }
// Use this for initialization void Start() { body = GetComponent <Rigidbody2D>(); animator = GetComponent <Animator>(); initialForceArrow = GetComponentInChildren <ForceArrow>(); cabinRenderer = transform.Find("ship cabin").GetComponent <SpriteRenderer>(); baseRenderer = transform.Find("ship base").GetComponent <SpriteRenderer>(); renderer = GetComponent <SpriteRenderer>(); baseColor = cabinRenderer.color; oldPos = transform.position; }