mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-20 09:24:32 -05:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user