EDITED:
Hello everyone.
I have a sphere that I am moving using rigidbody.velocity
. I would like to after a set time in this case 5 seconds tell the sphere to move in a new direction. For example the sphere starts moving to the left,after 5 seconds are up the sphere starts moving upwards. So after every 5 seconds that pass the sphere keeps changing it’s movement direction.
In order to achieve this I was thinking that I could keep track of the sphere’s position throughout its travel time.Then when the seconds are up I assign the position it is at as the new position.Another words I want to have the sphere take it’s current position as the new starting point from which it moves off.
I tried to do this by tracking the position of the sphere at run time and the after 5 seconds are up assigning it to a new variable.But that has gotten me nowhere.
This is my timer code:
function LateUpdate ()
{
print("late update");
ParticleMovement();///Function that controls sphere movement
if(movementTimer > 0)
{
movementTimer -= Time.deltaTime;
print(movementTimer);
}
if(movementTimer <= 0)
{
ParticleMovement();//I'm calling the movement function here when timer
//reaches zero so that the particles direction
//is chosen again.
movementTimer = newTimer;//Reset the timer back to 5 seconds every time
}
}
All hints are welcome
Thank you.