but my question is, how do I get the above 2 scripts to work with the following script that uses the keyboard to move around the scene:
var speed = 5.0;
function Update () {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);
}
I think I understand what you are asking. Your first script manipulates the camera while the second manipulates something called ‘mover’. Your third script is attempting to manipulate the camera correct?
Your issue, from what I see, is that your third script is trying to manipulate the position of the camera via transform.Translate (which changes the object’s position). Both scripts are fighting to change the same transform.
Here:
“transform.Translate(x, 0, z);” is being update at UPDATE
“transform.position = position + mover.position;” is being updated every late update which happens AFTER update which over writes UPDATE’s changes so you never get the changes done in UPDATE.
Here’s my idea how to solve this. It can be done in your first script and eliminates the need for the third:
var scrollScreen : boolean = false;
// Pick a scripted modifier or keypress to switch scrollScreen between true and false
if(scrollScreen) {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);
} else {transform.position = position + mover.position;}
It totally helped, thank you so much. And many apologies for my late reply. Yes, I ended up using the CapsLock key as the scrollScreen activator, but using GetKeyDown (which has to be called in the Update function) so that the script looks like this:
var mover : Transform;
var scrollScreen :boolean = false;
function Update () {
if (!target) {return;}
var speed = 5.0;
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
if(Input.GetKeyDown(KeyCode.CapsLock)){
scrollScreen = !scrollScreen ;
}
if(scrollScreen){
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);
} else {
transform.rotation = rotation;
transform.position = position + mover.position;
}
}
Please note: The above is not the entire script, just the revised portion that is being discussed in this posting. The rest of the script (can post upon request) is tweaked to exclude from the LateUpdate function those commands which are now included in the Update function.