Grid Dynamic Reveal/Raycasting

>Grid Dynamic Reveal works in the actual scene
>Created duplicate scene to practice impliment the King
>Layed out the full Grid on the terrain
>Used Raycasting to find the position of the cursor in 3D world space
>Have the object that is going to be placed follow the King's Cursor
This commit is contained in:
Katherine
2021-12-10 20:31:00 -06:00
parent 8c6de35fd7
commit 98d69fdfea
6 changed files with 964991 additions and 48 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b7527e2ad54cf254989fc23573a75b08
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,7 +7,7 @@ public class GridReveal : MonoBehaviour
private GameObject[] Rows;
private float TempKingPos = 0;
private int Index = 0;
private int ROSCount = 3;
private int ROSCount = 130;
void Start() {
List<GameObject> RowsList = new List<GameObject>();
@@ -28,6 +28,9 @@ public class GridReveal : MonoBehaviour
//A function for enabling and disabalimg the Visability of the King's Grid as the King Moves
public void DynGridReveal(float KingPos, float MovDir) {
if(KingPos > -670 || KingPos < -2960) { //Cancels out the function if the King is in the valley or the mountain
return;
}
if(TempKingPos >= KingPos + 20 || TempKingPos <= KingPos - 20) { //Moves the Grid Everytime is King has moved 20 Units
TempKingPos = KingPos;
if (MovDir == 0) {
@@ -42,8 +45,8 @@ public class GridReveal : MonoBehaviour
}
else if (MovDir <= 0) { //Moving Left
Rows[Index].SetActive(true);//Activates Rightmost
if (Index != 0 + ROSCount) {//Prevents OfB error
Rows[Index - ROSCount].SetActive(false);//Deactivates Leftmost
if (Index != 0) {//Prevents OfB error
Rows[Index + ROSCount].SetActive(false);//Deactivates Leftmost
Index--;
}
}

View File

@@ -4,10 +4,10 @@ using UnityEngine;
public class KingMove : MonoBehaviour
{
public float speed = 30.0f;
public float speed = 240.0f;
private Vector3 newPos;
private Vector3 MountCent = new Vector3(0, 30, -80);
private Vector3 MountCent = new Vector3(-4500, 620, 510);
public GameObject Grid;
// Update is called once per frame
void Update() {
@@ -17,33 +17,28 @@ public class KingMove : MonoBehaviour
translation *= Time.deltaTime;
// Move translation along the object's z-axis
if (transform.position.z <= 61 && transform.position.z >= -80) {
if (transform.position.x <= 350 && transform.position.x >= -4500) {
transform.Translate(translation, 0, 0);
Grid.GetComponent<GridReveal>().DynGridReveal(transform.position.z, translation); //Makes the grid reveal itself as the King moves
//transform.position = new Vector3(-42, 30, transform.position.z);
transform.rotation = Quaternion.Euler(0, 90, 0);
Grid.GetComponent<GridReveal>().DynGridReveal(transform.position.x, translation); //Makes the grid reveal itself as the King moves
transform.rotation = Quaternion.Euler(0, 180, 0);
}
else if (transform.position.z > 61) {
transform.position = new Vector3(-42, 30, 61);//Keeps them from going too far left
else if (transform.position.x > 350) {
transform.position = new Vector3(350, 625, 1130);//Keeps them from going too far left
}
else if (transform.position.z < -80) {//Once they rech a certain point they begin to cirlce around the mountain (radius of 42, x^2+(z+80)^2=42^2)
float x = transform.position.x;
x += translation; //Moves the player's X forward slightly
float z = -Mathf.Sqrt((42 * 42) - (x * x)) - 80; //Snaps the player onto a circle that is around the mountain, so the player orbits it smoothly
newPos = new Vector3(x, 30, z); //make a Vector3 out of the new X and Z
else if (transform.position.x < -4500) {//Once they rech a certain point they begin to cirlce around the mountain (radius of 1050, (x+4500)^2+(z-510)^2=620^2)
float z = transform.position.z;
z -= translation; //Moves the player's X forward slightly
float x = -Mathf.Sqrt((620 * 620) - ((z-510) * (z-510))) - 4500; //Snaps the player onto a circle that is around the mountain, so the player orbits it smoothly
newPos = new Vector3(x, 620, z); //make a Vector3 out of the new X and Z
transform.position = newPos;//Sets the player's new position on the cirlce
transform.LookAt(MountCent);//Rotates the player as they move along the circumfurance
/*if (RotStr == false) {//Rotates the player by 90 degrees once, to make LookAt work properly
transform.Rotate(0f, -90f, 0f);
RotStr = true;
}*/
if (x < -42) {//Snaps the player back onto the horizontal track
transform.position = new Vector3(-42, 30, -80);
if (z > 1130) {//Snaps the player back onto the horizontal track
transform.position = new Vector3(-4500, 625, 1130);
}
}
else {//If somehow the player disappears into the void, resets them
Debug.Log("Aw, Beans");
transform.position = new Vector3(-42, 30, 0);
transform.position = new Vector3(350, 625, 1130);
}
}
}

View File

@@ -2,8 +2,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KingPlace : MonoBehaviour
{
public class KingPlace : MonoBehaviour {
//Is called when the King clicks on the Block button
public void OnBlockClicked() {
PlaceObject(0);
@@ -30,10 +30,11 @@ public class KingPlace : MonoBehaviour
public GameObject Hail;
public GameObject Slime;
public GameObject Grid;
private GameObject Place;
private bool Placing = false;
private void PlaceObject(int ID) {
Grid.GetComponent<GridReveal>().GridSwitch(true);
//Switch statement, ID-0 = Block,ID-1 = Hail,ID-2 = Slime
GameObject Place;
switch (ID) {//Parses in the button clicked into the right object that the King is placing
case 0:
Debug.Log("B");
@@ -49,17 +50,27 @@ public class KingPlace : MonoBehaviour
break;
}
//Layout the grid
/* Have grid always existing? and Enable it for the King to see?
* Draw the grid dynamically based on the King's Camera?
* Draw it/Have it show up around the mouse cursor?
*/
Grid.GetComponent<GridReveal>().GridSwitch(true);
//The player selects where on the grid they want to place the object
/* Center anchored
* Should be "simple" to snap the cursor poistion onto the grid.
*/
Placing = true;
/* Center anchored
* Should be "simple" to snap the cursor poistion onto the grid.
*/
//The object is placed there
//Energy is spent
}
[SerializeField] private Camera KingCam;
[SerializeField] private LayerMask LayerMask;
private void Update() {
if(Placing == true) {
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) {
Place.transform.position = RayCastHit.point;
}
}
}
}

View File

@@ -6,34 +6,34 @@ EditorUserSettings:
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c7b151b180b6505263035233d1221fbd33134e7e422e0e8347129370bfb25
flags: 0
RecentlyUsedScenePath-1:
value: 224247031146467c0c03096f3d2c4a1e02161124623d28393930
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c7b151b180b6505263035233d1221fbd33134e7e422e0e8347129370bfb25
flags: 0
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c7b151b180b650d262f3d192c0e27d1e33136e7a923e7ee2e26
flags: 0
RecentlyUsedScenePath-4:
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c731f1415016439262f2434
flags: 0
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c7b151b180b65072128370c2b143febf4312bd6e225fda92f31352d1b
flags: 0
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c7b151b180b652b3a27292f260573f1e33136e7a923e7ee2e26
flags: 0
RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb
flags: 0
RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c7b151b180b65072128370c2b143febf4312bd6e225fda92f31352d1b
value: 22424703114646680e0b0227036c78111b125507233d28242c201373b3ae2136ebf32f
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c7b151b180b652b3a27292f260573f1e33136e7a923e7ee2e26
value: 22424703114646680e0b0227036c7b151b180b650721283704240d14e3f93637faa923e7ee2e26
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb
value: 22424703114646680e0b0227036c7b151b180b650721283704240d7df7ee3d2cfb
flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c7b151b180b650721283704240d7df7ee3d2cfb
value: 22424703114646680e0b0227036c7b151b180b650721283704240d14f0e12d3aedff78fce9332b25
flags: 0
UnityRemoteCompression:
value: 337f73