x


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;
   }
 }
more ▼

asked Jan 17 '12 at 01:15 AM

malcolmtwl gravatar image

malcolmtwl
26 2 3 4

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Jan 17 '12 at 08:38 AM

senad gravatar image

senad
641 3 5

erm ohk ty will try

Jan 19 '12 at 12:16 PM malcolmtwl
(comments are locked)
10|3000 characters needed characters left

This is the new code, i renamed the charactercontrollers differently and used this in my camera switcher code

more ▼

answered Jan 19 '12 at 01:30 PM

malcolmtwl gravatar image

malcolmtwl
26 2 3 4

(comments are locked)
10|3000 characters needed characters left

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; } }

more ▼

answered Jan 19 '12 at 01:30 PM

malcolmtwl gravatar image

malcolmtwl
26 2 3 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3127
x549
x241

asked: Jan 17 '12 at 01:15 AM

Seen: 352 times

Last Updated: Jan 19 '12 at 01:30 PM