Slime Temp and Bug fixes

>Fixed some bakes with the Hail
>Fixed the movement bugs with the king's movement
>Added the Slime in a semi-functional state
This commit is contained in:
Katherine
2022-02-10 15:54:16 -06:00
parent 3c1e36726a
commit 35c5c41f5a
7 changed files with 136 additions and 52 deletions

View File

@@ -8,16 +8,18 @@ public class Goo : MonoBehaviour
void FixedUpdate() {
Lifetime++;
if(Lifetime == 550) {
if(Lifetime == 950) {
Destruction();
}
}
//Makes the player sliperly whenever they step on the goo
void OnTriggerEnter(Collider other) {
Debug.Log("Slippy!");
GameObject player = other.gameObject;//Turns the collider into a game object
player.GetComponent<PlayerStats>().Traction = 1.5f;//Make it slippy
if (other.tag == "Player") {
Debug.Log("Slippy!");
GameObject player = other.gameObject;//Turns the collider into a game object
player.GetComponent<PlayerStats>().Traction = 1.5f;//Make it slippy
}
}
void Destruction() {

View File

@@ -16,6 +16,7 @@ public class HailArea : MonoBehaviour
int timer = 0;
RaycastHit hit;
[SerializeField] private LayerMask LayerMask;
float height = 0f;
// FixedUpdate is called once per .02 seconds (or 50 times a second)
void FixedUpdate()
@@ -29,8 +30,7 @@ public class HailArea : MonoBehaviour
//Random pos Z Zmax-radius -> Zmin+radius
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);
if (Physics.Raycast(position, transform.TransformDirection(Vector3.down), out hit, float.MaxValue, LayerMask)) {//Raycasts to find where the ground is
height = 100 - hit.distance;
}
position = new Vector3(position.x, 100+height, position.z); //find ground and set y occordingly

View File

@@ -46,11 +46,13 @@ public class KingMove : MonoBehaviour
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 (z > 1130) {//Snaps the player back onto the horizontal track
if (z >= -110) { //Stops this from breaking the circle's formula
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
}
else if (z > 1130) {//Snaps the player back onto the horizontal track
transform.position = new Vector3(-4500, 625, 1130);
}
}

View File

@@ -39,7 +39,7 @@ public class KingPlace : NetworkBehaviour
private GameObject Place;
private GameObject PlaceTemp;
private GameObject HailCorner;
private GameObject SlimeDir;
private int SlimeDir;
private bool FirstPlacing = false;
private bool HailPlacing = false;
private bool SlimePlacing = false;
@@ -93,13 +93,16 @@ public class KingPlace : NetworkBehaviour
{
HailCorner.transform.position = RayCastHit.point;
}
if (Input.GetMouseButtonUp(0)) {//Reads the player clicking the left mouse button again
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
CreateHail();
}
}
if (SlimePlacing == true) {
//TODO draw arrow in direction of slime move
//TODO CreateSlime function?
SlimeDir = DrawArrow();
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
PlaceTemp.GetComponent<Slime>().GooStart(SlimeDir);
SlimePlacing = false;
}
}
}
@@ -172,6 +175,11 @@ public class KingPlace : NetworkBehaviour
}
}
private int DrawArrow() {
//TODO convert mouse position to arrow direction. then return the int of what direction it is
return 2;
}
[ServerRpc(RequireOwnership = false)]
private void SpawnBoxServerRPC(Vector3 spawnLoc) {
boxPlaced = Instantiate(Block, spawnLoc, Quaternion.identity);

View File

@@ -4,46 +4,67 @@ using UnityEngine;
public class Slime : MonoBehaviour
{
float MoveDir;
float MoveSpd;
int GooTimer = 0;
Vector3 offset = new Vector3(0.0f, 0.4f, 0.0f);
bool GooGo = false;
Vector3 offset = new Vector3(0.0f, -0.1f, 0.0f);
Vector3 MoveDir = new Vector3(0, 0, 1);
RaycastHit hit;
public GameObject Goo;
public GameObject Folder;
public int StartPos = -29;
public int EndPos = -57;
[SerializeField] private LayerMask LayerMask;
// Start is called before the first frame update
void Start()
{
MoveDir = Time.deltaTime;
MoveSpd = 9*Time.deltaTime;
}
// FixedUpdate is called once per .02 seconds (or 50 times a second)
void FixedUpdate()
{
//create goo underneath them slime
if (GooTimer == 6) {
GameObject GooTrail = null;
GooTrail = Instantiate(Goo, transform.position - offset, transform.rotation);
GooTrail.transform.parent = Folder.transform;
GooTimer = 0;
if (GooGo == true) {//Makes it make goo and move only if it's already placed
//create goo underneath them slime
if (GooTimer == 6) {
GameObject GooTrail = null;
GooTrail = Instantiate(Goo, transform.position - offset, transform.rotation);
GooTrail.transform.parent = Folder.transform;
GooTimer = 0;
}
//attempt to move forward(Raycast infront for objects, and also raycast down, to make sure there's still ground underneath it)
if (Physics.Raycast(transform.position, transform.TransformDirection(MoveDir), out hit, 1.5f, LayerMask) || Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 50f, LayerMask)) {//turns it around when it hits something or is going to go over a pit//TODO hit more than terrain
MoveDir = -MoveDir;
}
transform.Translate(MoveSpd*MoveDir);//moving forward
GooTimer++;
}
//attempt to move forward(Raycast for objects, how to make sure it didn't fall off a cliff?)
if (transform.position.z >= StartPos || transform.position.z <= EndPos) {//Rough way of keeping turning it around when it reaches an end
MoveDir = -MoveDir;
}
//if can't Turn around 180 degrees
//otherwise actually move forward
transform.Translate(0, 0, MoveDir);
GooTimer++;
}
void OnTriggerStay(Collider other) {
//slow down player
GameObject player = other.gameObject;//Turns the collider into a game object
//Get the Player's speed
float CurVel = player.GetComponent<PlayerStats>().CurVel;
player.GetComponent<PlayerStats>().CurVel = CurVel - (CurVel/10);
//Cut it in half?
if (other.tag == "Player") {
//slow down player
GameObject player = other.gameObject;//Turns the collider into a game object
float CurVel = player.GetComponent<PlayerStats>().CurVel;//Get the Player's speed
player.GetComponent<PlayerStats>().CurVel = CurVel - (CurVel / 10);
//Cut it in half?
}
}
public void GooStart(int SlimeDir) {
GooGo = true;
switch (SlimeDir) {//Sets the slime's initial direction properly
case 0:
MoveDir = Vector3.back;
break;
case 1:
MoveDir = Vector3.left;
break;
case 2:
MoveDir = Vector3.forward;
break;
case 3:
MoveDir = Vector3.right;
break;
}
}
}