made wheel rotates and fixed collision - walls need box colliders adding

This commit is contained in:
Amaan Shawkath
2021-06-13 00:58:25 +01:00
parent 8b50f05957
commit a2eff81009
4 changed files with 286 additions and 15 deletions

View File

@@ -7,6 +7,8 @@ public class SpotController : MonoBehaviour
public GameObject sphere;
public GameObject visor;
public GameObject[] wheels;
public AudioSource backgroundSource;
public AudioSource sfxSource;
public AudioSource interactSource;
@@ -21,9 +23,10 @@ public class SpotController : MonoBehaviour
private float moveInput;
private float turnInput;
private float turnSpeed = 50f;
private float turnSpeed = 150f;
private Light light;
private bool blocked = false;
private void Start()
{
@@ -43,12 +46,37 @@ public class SpotController : MonoBehaviour
turnInput = Input.GetAxisRaw("Horizontal");
moveInput *= moveInput > 0 ? speed : revSpeed;
if (moveInput != 0 && wheels.Length > 0)
{
for (int i = 0; i < wheels.Length; i++)
{
wheels[i].transform.Rotate(0, 0, moveInput / 60 * 360 * Time.deltaTime);
}
}
;
float newRotation = turnInput * turnSpeed * Time.deltaTime * Input.GetAxisRaw("Vertical");
sphere.transform.Rotate(0, newRotation, 0, Space.Self);
transform.position = sphere.transform.position;
transform.rotation = sphere.transform.rotation;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, 1))
{
if (hit.transform.tag == "Wall")
{
blocked = true;
}
else
{
blocked = false;
}
}
else
{
blocked = false;
}
}
IEnumerator FlashRoutine()
@@ -64,7 +92,6 @@ public class SpotController : MonoBehaviour
renderer.material.SetColor("_EmissionColor", Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f));
}
}
private void LateUpdate()
{
if (moveInput != 0)
@@ -80,6 +107,7 @@ public class SpotController : MonoBehaviour
sfxSource.Stop();
}
sphere.transform.Translate(Vector3.forward * moveInput * Time.deltaTime, Space.Self);
if (!blocked && moveInput > 0)
sphere.transform.Translate(Vector3.forward * moveInput * Time.deltaTime, Space.Self);
}
}