King Grid and Hail

>King Grid should be fixed
>Hail has been updated having shadows spawn better
>This is achived through raycasting, and isn't perfect on sloped
surfaces
>King Place is also updated to fix some issues the networking caused
This commit is contained in:
Katherine
2022-02-08 13:37:53 -06:00
parent 9c15b44b6f
commit 3c1e36726a
6 changed files with 65 additions and 32 deletions

View File

@@ -16,13 +16,13 @@ public class Hail : MonoBehaviour
hail = GetComponent<Rigidbody>();//Gets the rigidbody attached to the bolder
ShadTemp = Instantiate(shadow);//Creates the shadow
ShadTemp.transform.position = new Vector3(hail.transform.position.x, 0, hail.transform.position.z);//Sets it properly directly under the hail //TODO find ground and set it's y ocordingly
ShadTemp.transform.position = new Vector3(hail.transform.position.x, hail.transform.position.y - 99.9f, hail.transform.position.z);//Sets it properly directly under the hail and .1 above the ground
ShadTemp.transform.localScale = new Vector3(ShadStSz, 0, ShadStSz);//Scales it to the proper start size
m = (hail.transform.localScale.x - ShadStSz) / 100;//Find the proper rate of growth
m = hail.transform.localScale.x / 99.9f;//Find the proper rate of growth
}
void FixedUpdate() {
float y = m * (hail.transform.position.y-100) + ShadStSz;//Find the proper current size
float y = -m * (hail.transform.position.y - ShadTemp.transform.position.y) + hail.transform.localScale.x;//Find the proper current size
ShadTemp.transform.localScale = new Vector3(y, 0, y);//Scales the shadow to that size
Destruction();//Sees if it needs to destroy both
}
@@ -44,7 +44,7 @@ public class Hail : MonoBehaviour
//Destroys the Hail and its shadow
void Destruction() {
if(hail.transform.position.y <= 0) {
if(hail.transform.position.y <= ShadTemp.transform.position.y) {
Destroy(ShadTemp);
Destroy(gameObject);
}

View File

@@ -14,6 +14,9 @@ public class HailArea : MonoBehaviour
public GameObject Hail;
int timer = 0;
RaycastHit hit;
float height = 0f;
// FixedUpdate is called once per .02 seconds (or 50 times a second)
void FixedUpdate()
{
@@ -24,7 +27,13 @@ public class HailArea : MonoBehaviour
float radius = diameter / 2.0f;
//Random pos X Xmax-radius -> Xmin+radius
//Random pos Z Zmax-radius -> Zmin+radius
Vector3 position = new Vector3(Random.Range(Xmin + radius, Xmax - radius), 100, Random.Range(Zmin + radius, Zmax - radius)); //TODO find ground and set y occordingly
Vector3 position = new Vector3(Random.Range(Xmin + radius, Xmax - radius), 100, Random.Range(Zmin + radius, Zmax - radius));//Finds where the hail will spawn in the air
if (Physics.Raycast(position, transform.TransformDirection(Vector3.down), out hit, float.MaxValue)) {//Raycasts to find where the ground is
Debug.DrawRay(position, transform.TransformDirection(Vector3.down) * 100, Color.yellow);
height = 100 - hit.distance;
}
position = new Vector3(position.x, 100+height, position.z); //find ground and set y occordingly
SpawnHail(diameter, position);
}

View File

@@ -77,7 +77,7 @@ public class KingPlace : NetworkBehaviour
[SerializeField] private Camera KingCam;
[SerializeField] private LayerMask LayerMask;
private void FixedUpdate() { //TODO Canceling out an input
private void Update() { //TODO Canceling out an input
if (FirstPlacing == true) {
Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);//Raycast to find the point where the mouse cursor is
if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) {
@@ -121,11 +121,15 @@ public class KingPlace : NetworkBehaviour
// Calculate the position to spawn at
Vector3 spawnLoc = new Vector3(x, PlaceTemp.transform.position.y, z);
// Have the server spawn the box
SpawnBoxServerRPC(spawnLoc);
PlaceTemp.transform.position = spawnLoc;
// Remove the reference to PlaceTemp
Destroy(PlaceTemp);
if (Place == BlockWithoutNetwork) {
// Have the server spawn the box
SpawnBoxServerRPC(spawnLoc);
// Remove the reference to PlaceTemp
Destroy(PlaceTemp);
}
}
if (Place == Slime) {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function
@@ -138,7 +142,7 @@ public class KingPlace : NetworkBehaviour
}
}
private void GridCheck(int Row, int Box, ref bool Placing) {
private void GridCheck(int Row, int Box, ref bool Placing) {//TODO change to Try Catch
GameObject RowTrue;
GameObject BoxTrue;
RowTrue = Grid.transform.Find("Row" + Row).gameObject;