Skip to content

Commit

Permalink
Add raycast distance and scaling to targeting reticle
Browse files Browse the repository at this point in the history
  • Loading branch information
FredEckert committed Jan 18, 2019
1 parent fa782ef commit 2f6f029
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Assets/_TailGunner/Prefabs/EnemyShipPrefab.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Size: {x: 3, y: 3, z: 7}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114562699034414116
MonoBehaviour:
Expand All @@ -126,5 +126,5 @@ MonoBehaviour:
segments: 250
doLoop: 1
speed: 0.1
showSpline: 1
showPoints: 1
showSpline: 0
showPoints: 0
52 changes: 26 additions & 26 deletions Assets/_TailGunner/Scripts/TailgReticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class TailgReticle : MonoBehaviour {

public static VectorLine Reticle;
public float reticleScale = 0.001f;
private float defaultPosZ;

public static TailgReticle use;

Expand All @@ -15,53 +16,52 @@ public virtual void Awake()
TailgReticle.use = this;
}

public void StartUp() {

public void StartUp()
{
//Set up target reticle lines and colors...
//
//set reticle to one meter in front of player
//set reticle up 1.7 meters to match player's offset from zero
this.gameObject.transform.position = new Vector3(0, 1.7f, 1);
//set reticle distance to just inside far clip plane
defaultPosZ = 1860f;
this.gameObject.transform.position = new Vector3(0, 1.7f, defaultPosZ);
this.gameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
//scale reticle
for (int index = 0; index < LineData.use.reticlePoints.Count; index++)
{
Vector3 point = LineData.use.reticlePoints[index];
//point.x = point.x + 30f;
//point.y = point.y + 20f;
//point.y = point.y + (1 / this.reticleScale);
point = point * this.reticleScale;
LineData.use.reticlePoints[index] = point;
}

//Create reticle
Reticle = new VectorLine(gameObject.name, LineData.use.reticlePoints, Manager.use.lineWidth);
Reticle.material = Manager.use.lineMaterial;
Reticle.texture = Manager.use.lineTexture;
Reticle.color = Manager.use.colorNormal;
Reticle.capLength = Manager.use.capLength;

// Make VectorManager lines be drawn in the scene instead of as an overlay
VectorManager.useDraw3D = true;
// Make this transform have the vector line object that's defined above
VectorManager.ObjectSetup(gameObject, Reticle, Visibility.Dynamic, Brightness.None);

//TailgUI.Reticle = this.MakeLine("Reticle", LineData.use.reticlePoints);
//TailgUI.Reticle.color = Manager.use.MultiplyColor(Manager.use.colorNormal, 0.75f);
//TailgUI.Reticle.color = Manager.use.colorNormal;
//this.SetReticleLines();
//TailgUI.Reticle.active = false;

//public virtual void SetReticleLines()
//{
// //Manager.use.ScalePointsToScreen(TailgUI.targetReticleNormal.points2);
// //Manager.use.ScalePointsToScreen(TailgUI.targetReticleActive.points2);
// TailgUI.Reticle.Draw3D();
//}

}

// Update is called once per frame
void Update () {

void Update()
{
Transform camera = Camera.main.transform;
Ray ray = new Ray(camera.position, camera.rotation * Vector3.forward);
RaycastHit hit;
float distance;
if (Physics.Raycast(ray, out hit))
{
distance = hit.distance;
Reticle.color = Manager.use.colorIntense;
}
else
{
distance = defaultPosZ;
Reticle.color = Manager.use.colorNormal;
}
transform.localPosition = new Vector3(0, 0, distance);
transform.localScale = Vector3.one * distance;
}

}
2 changes: 1 addition & 1 deletion Assets/_TailGunner/_TailGunner.unity
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ SphereCollider:
m_GameObject: {fileID: 342820801}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
Expand Down
5 changes: 3 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 14
serializedVersion: 15
productGUID: 8831970a4c3047343afe17fe0168d819
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
Expand Down Expand Up @@ -239,7 +239,7 @@ PlayerSettings:
tvOSManualSigningProvisioningProfileID:
appleEnableAutomaticSigning: 0
clonedFromGUID: 00000000000000000000000000000000
AndroidTargetDevice: 0
AndroidTargetArchitectures: 5
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName:
Expand Down Expand Up @@ -411,6 +411,7 @@ PlayerSettings:
switchAllowsVideoCapturing: 1
switchAllowsRuntimeAddOnContentInstall: 0
switchDataLossConfirmation: 0
switchUserAccountLockEnabled: 0
switchSupportedNpadStyles: 3
switchSocketConfigEnabled: 0
switchTcpInitialSendBufferSize: 32
Expand Down

0 comments on commit 2f6f029

Please sign in to comment.