Is it possible to delay the effects of a script that is attached to a game object?
I have 2 characters in a scene, both receiving live motion capture data, so they are both animated identically. I have rotated one by 180 degrees and placed it in front of the other one, to create the impression that they are copying/mirroring each other.
Each has several scripts attached to them, of course...
Now, I would like to be able to delay one character a bit (e.g. 1 sec) to make it look more realistic, as if one character is observing the other character and then copying its exact movements.
Is it possible to do this by somehow using the Invoke
method on the other character's Update
perhaps? Or any other possibilities to achieve what I described?
EDIT :: I used a buffering mechanism, as suggested by all the helpful comments and answers, instead of delaying, because delaying would have resulted in the same network data being used, except after a delay, but I needed the same old data being used to animate a second character to create the impression of a delayed copying...
private Queue<Vector3[]> posQueue;
private Queue<Quaternion[]> rotQueue;
int delayedFrames = 30;
void Start()
{
posQueue = new Queue<Vector3[]>();
rotQueue = new Queue<Quaternion[]>();
}
void Update()
{
Vector3[] latestPositions;
Quaternion[] latestOrientations;
if (mvnActors.getLatestPose(actorID-1, out latestPositions, out latestOrientations))
{
posQueue.Enqueue(latestPositions);
rotQueue.Enqueue(latestOrientations);
if ((posQueue.Count > delayedFrames) && (rotQueue.Count > delayedFrames))
{
Vector3[] delayedPos = posQueue.Dequeue();
Quaternion[] delayedRot = rotQueue.Dequeue();
updateMvnActor(currentPose, delayedPos, delayedRot);
updateModel(currentPose, targetModel);
}
}
}
BeginInvoke
andEndInvoke
- async calling, you could make the async thread sleep at the beginning effectively delaying its execution. I would not however recommend this approach(threads can cause a lot of overhead!) - see comment above. \$\endgroup\$ – wondra Nov 2 '15 at 23:23