Record camera and play again....

I am working on a project… in which i want to have a “record” button, when user push it, and moves camera around in the scene… (users have access to camera movement) there should be another button, which saves current states… this way user goes on saving various states… and switch off the “record button” now when user hits “play button” camera should show or follow total animation from the state 1 to last state… It is like creating animation and all before presentation and playing it… to avoid hustle to adjust camera views and all during the presentation…

I think it can be done by recording camera position at each point when user clicks “create state” button… and then playing it sequentially… but what about othes objests…( they have only positions animated) [i can think of it, but i have no idea how i can sript it out… :)] i have no idea about making an object to move from one position to another position… i tried to find it in refrence documentation but icant get it… thank u in advance…

@iwaldrop Can you tell me how to do it???? i'm unable to...

1 Answer

1

Here’s a really simple script to get you started… 1.5 years after you asked the question since you bumped it still needing help…

Attach it to your camera and give it a run. Look over the script and see what it’s doing, then go from there with doing something more complex.

Edit : Oh, and if you actually want to “save” what you’re recording, have a look at the FPSInputTracker I wrote a while back for some ideas on doing that with XML. You can get the files from the 4th post on that forum topic.

using UnityEngine;
using System.Collections;
using System.Collections.Generic ;

public class YourClassName : MonoBehaviour
{
	[System.Serializable]
	//simple class for values we're going to record
	public class GoVals
	{
		public Vector3 position ;
		public Quaternion rotation ;

		//constructor
		public GoVals(Vector3 position, Quaternion rotation)
		{
			this.position = position ;
			this.rotation = rotation ;
		}
	}

	//a list of recorded values
	List<GoVals> vals = new List<GoVals>() ;
	//are we recording?
	bool recording = false ;
	//...are we replaying?
	bool replaying = false ;
	//while replaying, an int to keep track of which frame we're on
	int replayFrame = 0 ;

	//cache of our transform
	Transform tf ;

	void Start()
	{
		//cache it...
		tf = this.transform ;
	}

	void Update()
	{
		Record() ;
		Replay() ;
	}

	void Record()
	{
		if(!recording) return ;

		//add a new value to our recorder list
		vals.Add(new GoVals(tf.position, tf.rotation)) ;
	}

	void Replay()
	{
		if(!replaying) return ;

		//if the frame we're going to try to replay exceeds available replayable frames...
		if(replayFrame >= vals.Count)
		{
			replayFrame = 0 ;
			replaying = false ;
			//uncomment the next line if you want it to make a new recording next time, otherwise it will continue from where it left off
			//vals = new List<GoVals>() ;
			return ;
		}
		//set our transform values
		tf.position = vals[replayFrame].position ;
		tf.rotation = vals[replayFrame].rotation ;
		//increment our frame
		replayFrame ++ ;
	}

	void OnGUI()
	{
		if(!replaying)
		{
			if(GUILayout.Button(recording ? "Stop Recording" : "Record"))
				recording = !recording ;
		}

		if(!recording)
		{
			if(GUILayout.Button(replaying ? "Stop Replay" : "Replay"))
				replaying = !replaying ;
		}
	}
}

Thank you sir!!

if i add tf = GameObject.FindWithTag ("Player").transform; it will record object with tag "Player" movements but how could i record more objects at once?

2025, still very helpful! Thanks!