Genesis Phase III – Relative Sun

Posted: August 7, 2013 in Game Programming and Design

To keep the sun at a constant distance from my ship, I’ve done a couple things.

First, the Star.cs object has a GameObject called PlayerObject attached to it with public scope.  I then reference the player ship here.  From there, I add a second public float called RelativeDistanceFromPlayer.  This is how far I wish to keep the sun object from the ship at all times (the Z plane).

For right now I have set this at 5000.0f, which should push the sun 5000 away from the ship and toward the ship as the ship turns to it or away from it.

if (PlayerObject != null && RelativeDistanceFromPlayer > 0.0f)

//keep the Z axis the relative distance from the player
Vector3 sunPosition = this.transform.position;
sunPosition.Set (PlayerObject.transform.position.x, PlayerObject.transform.position.y, PlayerObject.transform.position.z – RelativeDistanceFromPlayer);
this.transform.position = sunPosition;


All that is left is to add a targeting panel now and Phase III is complete.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s