- Home /
Singling out mutiple Character movement
Hi, my game consists of two characters which means i have two character controllers (default). Whenever i switch cameras and move both characters move together, when i only need to move the character i am focusing on.
To switch between characters i use this code (Characters have 2 cameras each) :
Character1 > Camera 1 and 2
Character2 > Camera 3 and 4
var camera1 : Camera; var camera2 : Camera; var camera3 : Camera; var camera4 : Camera;
public var startCamera : int = 1;
function Start () { camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; startCamera = 1; }
function Update () { if (Input.GetKeyDown ("c") && (startCamera == 1)) { startCamera = 3; camera1.enabled = false; camera2.enabled = false; camera3.enabled = true; camera4.enabled = true; }
else if (Input.GetKeyDown ("c") && (startCamera == 3)) { startCamera = 1; camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; } }
Answer by senad · Jan 17, 2012 at 08:38 AM
I am guessing that your character controllers are listening on user inputs and do not know if the character is actually active or not. In that case you can add a simple if-statement which checks if the character is currently active and should be moved / controlled or not.
For example you could check on the startCamera variable or define a flag in the controller script, which you turn on or off when you switch characters.
Answer by malcolmtwl · Jan 19, 2012 at 01:30 PM
This is the new code, i renamed the charactercontrollers differently and used this in my camera switcher code
Answer by malcolmtwl · Jan 19, 2012 at 01:30 PM
var camera1 : Camera; var camera2 : Camera; var camera3 : Camera; var camera4 : Camera;
var Tumble : MonoScript; var Blueboy : MonoScript;
public var startCamera : int = 1;
function Start () { camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false; startCamera = 1; Tumble.enabled = true; Blueboy.enabled = false; }
function Update () { if (Input.GetKeyDown ("c") && (startCamera == 1)) { startCamera = 3; camera1.enabled = false; camera2.enabled = false; camera3.enabled = true; camera4.enabled = true;
Tumble.enabled = false; Blueboy.enabled = true; }
else if (Input.GetKeyDown ("c") && (startCamera == 3)) { startCamera = 1; camera1.enabled = true; camera2.enabled = true; camera3.enabled = false; camera4.enabled = false;
Tumble.enabled = true; Blueboy.enabled = false; } }
Your answer
Follow this Question
Related Questions
setting a character controller orientation by script 1 Answer
Swapping Cameras Disables Keyboard Input 3 Answers
UI Buttons switch cameras 3 Answers
Main Camera Switch? 3 Answers