Commit 3c33863e authored by Nathan Hertz's avatar Nathan Hertz

Merge branch 'master' of git.cs.nmt.edu:nhertz/game-jam-f2k16

parents eb8b4053 d56e10dd
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Moon
{
public GameObject obj { get; set; }
public float orbitRadius { get; set; }
public float orbitSpeed { get; set; }
public Vector3 axis { get; set; }
public Moon(float scale)
{
obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.transform.localScale = new Vector3(scale, scale, scale);
}
public void UpdatePosition(Vector3 center)
{
obj.transform.RotateAround(center, axis, Time.deltaTime * orbitSpeed);
obj.transform.position = Vector3.MoveTowards(
obj.transform.position, (obj.transform.position - center).normalized * orbitRadius + center,
Time.deltaTime * orbitSpeed);
}
}
public class Orbit : MonoBehaviour
{
public float thrust;
public Rigidbody rb;
public GameObject earth;
void Start()
{
rb = GetComponent<Rigidbody>();
earth = GameObject.Find("Earth");
}
void FixedUpdate()
{
rb.AddForce(10 * (Quaternion.Euler(0, 0, 90) * (earth.transform.position + transform.position)));
}
public List<Moon> moons;
void Start()
{
moons = new List<Moon>();
float earthRadius = transform.localScale.x;
// Create moons closer to the earth than to the player.
for (float i = 0; i < 10; i++)
{
// Size of moon.
float scale = 5.0f + ((i + 3) % 2);
Moon m = new global::Moon(scale);
// Orbit radius and speed
m.orbitRadius = earthRadius + 25 + i * 5;
m.orbitSpeed = 40.0f + 5 * ((i + 2) % 3);
// Axis of rotation
float off = i * 30;
Quaternion quat = Quaternion.Euler(off, -off * 3, off * 4);
m.axis = quat * Vector3.up;
// Initial position
m.obj.transform.position = quat * new Vector3(m.orbitRadius, 0, 0) + transform.position;
m.UpdatePosition(transform.position);
moons.Add(m);
}
// Create moons with an orbit radius larger than the player's radius.
for (float i = 0; i < 10; i++)
{
// Size of moon.
float scale = 50.0f + ((i + 3) % 2) * 4;
Moon m = new global::Moon(scale);
// Orbit radius and speed
m.orbitRadius = earthRadius + 500 + i * 100;
m.orbitSpeed = 200.0f + i * 10;
// Axis of rotation
float off = i * 30;
Quaternion quat = Quaternion.Euler(off, -off * 3, off * 4);
m.axis = quat * Vector3.up;
// Initial position
m.obj.transform.position = quat * new Vector3(m.orbitRadius, 0, 0) + transform.position;
m.UpdatePosition(transform.position);
moons.Add(m);
}
foreach(Moon m in moons)
m.orbitSpeed /= 10.0f;
}
void FixedUpdate()
{
foreach (Moon m in moons)
{
m.UpdatePosition(transform.position);
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment