Skip to content

Commit

Permalink
remove unnecessary GetComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Oxropy committed Oct 6, 2020
1 parent 8721d74 commit 22d2d55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions Assets/Scripts/Ball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ public void PlaceInOrbit()
// v = sqrt(GM * (2/r - 1/a))
// a = 1/2 of longest axis
var startPlanet = world.startPlanet;
var planet = startPlanet.GetComponent<GravityObject>();
transform.position = startPlanet.transform.position;
var distance = Random.Range(planet.radius * 1.5f + radius * 2, planet.radiusGravity - radius);
var distance = Random.Range(startPlanet.radius * 1.5f + radius * 2, startPlanet.radiusGravity - radius);
transform.Translate(distance, 0, 0);
var a = Random.Range((distance + startPlanet.radius * 1.5f + radius) / 2, (distance + planet.radiusGravity - startPlanet.radius - radius) / 2);
var a = Random.Range((distance + startPlanet.radius * 1.5f + radius) / 2, (distance + startPlanet.radiusGravity - startPlanet.radius - radius) / 2);
var orbitModifier = (2 / distance - 1 / a);
velocity = Vector3.forward * Mathf.Sqrt(G * startPlanet.mass * orbitModifier);
frozen = false;
Expand Down Expand Up @@ -245,10 +244,8 @@ private void DrawTrajectory()
DrawTrajectory(_planTrajectory, Color.white, Color.green, world.lr2);
}

private void DrawTrajectory(Trajectory trajectory, Color color, Color colorStable, LineRenderer go)
private static void DrawTrajectory(Trajectory trajectory, Color color, Color colorStable, LineRenderer lr)
{
LineRenderer lr = go.GetComponent<LineRenderer>();

if (trajectory == null || trajectory.IsEmpty())
{
lr.enabled = false;
Expand All @@ -271,7 +268,6 @@ private void DrawTrajectory(Trajectory trajectory, Color color, Color colorStabl
lr.positionCount = i +1;
lr.SetPosition(i, position);
}

}

#if UNITY_EDITOR
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Trajectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public bool CalculateNext(float dtSince, out Vector3 position, out Vector3 veloc
return true;
}

public Planet FindPlanetAround(Planet current, World world, float ballRadius, Vector3 pos, out Vector3 delta)
public static Planet FindPlanetAround(Planet current, World world, float ballRadius, Vector3 pos, out Vector3 delta)
{
delta = Vector3.zero;
if (current != null)
Expand Down

0 comments on commit 22d2d55

Please sign in to comment.