Disable character controller when in turret

Hi…

Im making a virtual environment where a character can walk up to a gun turret and can hop into it an look around.

Ive been able to get the camera to swap to the turret aswell as the mouse look.

But i can still see the character moving around when i press the movement keys.

Im just wondering if there is anyway to disbale the ‘character motor’ component of the character while im in the turret

This is my script so far. Im using JAVA

2 Answers

2

var camera1 : GameObject;
var camera2 : GameObject;
var turret_camera : Camera;

private var inturret : int;

function Start () {
   camera1.active = true;
   camera2.active = false;
   turret_camera.camera.enabled = false;
   inturret = 0;
   GetComponent("Character Motor (Script)").enabled = false;
   }

function Update () {
   if (Input.GetKeyDown ("e")){
		if (inturret == 0){
      camera1.active = false;
      camera2.active = true;
	  turret_camera.camera.enabled = true;
	  //camera1.GetComponent("CharacterMotor").enabled = false;
	  inturret = 1;
	  }
	  else{
	  camera1.active = true;
	  camera2.active = false;
	  turret_camera.camera.enabled = false;
	  //camera1.GetComponent("CharacterMotor").enabled = true;
	  inturret = 0;
	  }
   }
  
}`
`

You probably need to call the GetComponent() method from the game object that you are using for your character, not the camera. i.e... whichever gameObject you have in the scene that currently has the CharacterMotor component attached to it... that is the one you'll need to turn off.

heres how u can disable the CharacterController, or any other component with this line

js:
  var player : GameObject;
    player.GetComponent("CharacterController").enabled = false;

c# 
  public GameObject player;
    player.GetComponent<CharacterController>().enabled = false;

u just need to add the player in the inspector and u r set