Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
1.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BabyController : MonoBehaviour
{
private Vector3 currentVector;
[HideInInspector]
public Vector3 targetVector;
private Rigidbody rb;
private YeetHandle yeetHandle;
public float speed;
private float timer = 0;
public float minRandTimer;
public float maxRandTimer;
public float randTimer;
void Start()
{
rb = GetComponent<Rigidbody>();
yeetHandle = GetComponent<YeetHandle>();
currentVector = RandomNormVector();
targetVector = RandomNormVector();
randTimer = Random.Range(minRandTimer, maxRandTimer);
}
void FixedUpdate()
{
if(!yeetHandle.held)
{
currentVector = Vector3.Slerp(currentVector, targetVector, Time.deltaTime);
rb.MovePosition(transform.position + (currentVector * speed));
}
timer += Time.deltaTime;
if (timer > randTimer)
{
targetVector = RandomNormVector();
timer = 0;
randTimer = Random.Range(minRandTimer, maxRandTimer);
}
}
public Vector3 RandomNormVector()
{
float _x = Random.Range(-1f, 1f);
float _z = Random.Range(-1f, 1f);
return new Vector3(_x, 0, _z).normalized;
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position, transform.position + currentVector);
}
}