When the object rotate around the target make the transform change the height randomly every each X seconds?
For example make that each time take the transform to change to the new random height X duration time then stay at that height Y duration time in seconds then change to the next random height.
Now the transform change height’s but never rotate around anymore.
I want it to rotate around the target and change height randomly at the same time.
I tried to do it with this part in the script :
Vector3 radiusPosition = new Vector3(target.position.x, Mathf.Lerp(0,
target.position.y + setRandomHeight, t), dc.xRadius);
t += 0.1f * Time.deltaTime;
if(t >= 1.0f)
{
setRandomHeight = Random.Range(0, setRandomHeight);
t = 0.0f;
}
but it’s not duration time and not what i wanted and it’s not rotating around anymore it’s just staying at place and only change the height randomly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateAroundTarget : MonoBehaviour
{
public Transform target;
public float speed;
public Vector3 axis;
public bool randomHeight;
public float setRandomHeight = 1;
public DrawCircle dc;
private float lastRadius;
private bool move = false;
private float t = 0.0f;
private void Start()
{
lastRadius = dc.xRadius;
move = true;
if(randomHeight)
{
setRandomHeight = Random.Range(0, setRandomHeight);
}
}
private void Update()
{
Vector3 radiusPosition = new Vector3(target.position.x, Mathf.Lerp(0,
target.position.y + setRandomHeight, t), dc.xRadius);
t += 0.1f * Time.deltaTime;
if(t >= 1.0f)
{
setRandomHeight = Random.Range(0, setRandomHeight);
t = 0.0f;
}
if (move == false)
{
transform.RotateAround(target.position, axis, speed * Time.deltaTime);
}
if (lastRadius != dc.xRadius)
{
move = true;
lastRadius = dc.xRadius;
}
if(move)
{
if (transform.position != radiusPosition)
{
float step = 1 * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position,
radiusPosition, step);
}
else
{
move = false;
}
}
}
}