Last active
August 29, 2015 14:24
-
-
Save Stektpotet/1f45c4b681886482afeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(Rigidbody2D))] | |
public abstract class TimeDilated : MonoBehaviour | |
{ | |
private float _time = 0; | |
public float localTime { get{ return _time; } set{_time = value;} } | |
public Vector2 velocity; | |
protected Vector2 _dilationForce = Vector2.zero; //acceleration | |
public Vector2 acceleration{ get{ return _dilationForce; } set { _dilationForce = value; } } | |
public float dilation{ get{return 1/(_dilationForce.magnitude * 20 + 1);} } | |
public float localDilation{get{return dilation/World.dilation;}}//the dilation used internally; | |
public bool isFocus; //temporary boolean, this will be controlled by World-script | |
Rigidbody2D rigid; | |
void Start() | |
{ | |
if(isFocus) | |
{ | |
World.dilationFocus = this; | |
} | |
rigid = GetComponent<Rigidbody2D>(); | |
rigid.velocity = velocity; | |
} | |
public void PassTime() | |
{ | |
_time += Time.deltaTime * localDilation; // if this is the dilatoinFocus time will pass as normal; | |
// Debug.Log (name + "time is: " + _time); | |
} | |
void FixedUpdate() | |
{ | |
//TODO FIXME This is the part I need help with | |
velocity += acceleration; | |
rigid.velocity = velocity; | |
acceleration = Vector2.zero; | |
} | |
void Update() | |
{ | |
PassTime(); | |
if(isFocus) | |
{ | |
World.PassTime(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimeDilator : MonoBehaviour | |
{ | |
public float areaOfEffect = 5; | |
void FixedUpdate() | |
{ | |
Collider2D[] cols = Physics2D.OverlapCircleAll((Vector2)transform.position, areaOfEffect); | |
for(int i=0; i < cols.Length; i++) | |
{ | |
TimeDilated td = cols[i].GetComponent<TimeDilated>(); | |
if(td != null) | |
{ | |
Vector2 relative = (transform.position-td.transform.position); | |
td.acceleration += areaOfEffect/(1+relative.magnitude)*relative.normalized; | |
} | |
} | |
} | |
void OnDrawGizmos() | |
{ | |
Gizmos.color = new Color (0.1f, 0.1f, 0.1f, 0.1f); | |
Gizmos.DrawSphere (transform.position, areaOfEffect); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class World | |
{ | |
public const float DEFAULTDILATION = 1; | |
private static float _time = 0; | |
public static float time { get{ return _time; } set{_time = value;} } | |
public static TimeDilated dilationFocus; // the time dilated object in focus. | |
public static float dilation{ get{return (dilationFocus != null) ? dilationFocus.dilation : DEFAULTDILATION;} } | |
public static void PassTime() | |
{ | |
_time += Time.deltaTime * dilation; | |
// Debug.Log ("Worldtime is: " + _time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment