How can I state all character movements for FPS?

Hello. I’m new to Unity, as well as C# and JS. I’m trying to do from “scratch” a FPS game, to build up my understanding of the developing of the games. Anyway, this is what I have so far :slight_smile:

I have imported the FPS Character Controller from Unity and so far have the gun and cameras aligned properly.

This is my code for Player_State.JS.

var Crouching: float = 4;
var Sprinting: float = 10;
var Grounding: float = 2.5;
var WhenShooting: float = -0.5;
var WalkAim: float = 4;
var CrouchAim: float = 2.5;
var GroundAim: float = 1.5;
//player control
var BossC: CharacterController;
var PlayerS: float;
var PMotor: CharacterMotor;
var Anim: GameObject;
var JumpAnim: GameObject;
//types of especial movement
var Jump: boolean = false;
var Crouch: boolean = false;
var Ground: boolean = false;
var Sprint: boolean = false;
var Reload: boolean = false;
var Aiming: boolean = false;
//for shooting
var CanShoot: boolean = false;
var Shoot: boolean = false;
var Mag: float = 32;
var Bullets: float;
var MaxAmmo: float = 256;
//extras
var CharacterMag;
//Player States = -1: long idle, 0: idle, 1: walk, 2: sprint, 3: crouch, 4: ground, 5:aim, 6: shoot, 7:reload


function Start () {
	PlayerS=0;
	Bullets=32;
	
}

function Update () {
	Player_State ();
	Player_Anims ();
	CharacterMag = BossC.velocity.magnitude;
	ReloadYes ();
	Is_Shooting ();

}

function ReloadYes () 
{

if (Bullets<=32 && Bullets >0 &&!Input.GetButton("Sprint") && BossC.isGrounded)
	{
	CanShoot=true;
	}
else if (Bullets==0)
	{
	CanShoot=false;
	Reload=true;
	{
else if (Bullets<32 && Bullets>0)
	{
	Reload=true;
	}
else if (Bullets==32)
	{
	Reload=false;
	}
else if (Reload && Input.GetButton("Reload") &&! Input.GetMouseButton(1) &&! Input.GetMouseButton(0) &&!Input.GetButton("Sprint") && BossC.isGrounded)
	{
	Reloading=true;
	}
}

function Is_Shooting ()
 { 

	if (CanShoot)
		{
		if (Input.GetMouseButton(1))
			{
			Shoot=true;
			if (Input.GetMouseButtonUp(1))
				{
				Shoot=false;
				BroadcastMessage("Shoot", false, SendMessageOptions.DontRequireReceiver);
				}
			}
		}
	if (Shoot)
		{BroadcastMessage("Shoot", true, SendMessageOptions.DontRequireReceiver);
}

function Player_State () 
{ 

if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") !=0) 
//If character moves
	{
	if (Input.GetButton("Sprint") &&! Input.GetMouseButton(1) &&! Input.GetMouseButton(0)) 
	//if character sprints
		{
		PlayerS=2;
		}
	else if (Input.GetMouseButton(0) &&! Input.GetButton("Sprint") && BossC.isGrounded) 
	//if character aims
		{
		Aiming=true;
		}
	else if (Input.GetButton('Crouch') &&! Input.GetButton("Sprint"))
	 //if character crouches
		{
		Crouch=true;
		}
	else 
	//if character moves but does no special movement, just walks
		{
		PlayerS=1;
		}
	}
else if (Input.GetMouseButton(0) &&! Input.GetButton("Sprint"))  
//if character aims
	{
	Aiming=true;
	}
else if (Input.GetButton('Jump') && !BossC.isGrounded) 
//if character jumps
	{
	Jump=true;
	}
else if (Input.GetButton('Crouch')  && PlayerS&&! Input.GetButton("Sprint")) 
//if character crouches
	{
	Crouch=true;
	}
else
	{
	//if character stays idle for long
	if (Time.deltaTime>=10.0) 
		{
		PlayerS=-1;
		}
	else
		{
		//if character is not moving, idle
		PlayerS=0; 
		
		}
	}

}
function Player_Anims () 
{ 

if (PlayerS==0) 
//animation for player idle
	{
	PMotor.animation.CrossFade('Idle', 0.2);
	}
else if (PlayerS==-1 ) 
//animation for long player idle
	{
	PMotor.animation.CrossFade('LongIdle', 0.2);
	}
else if (PlayerS==1 && BossC.isGrounded) 
//animation for walking, speed
	{
	Anim.animation["Walk"].speed = CharacterMag/Walking;
    Anim.animation.CrossFade("Walk", 0.2);
	PMotor.movement.maxForwardSpeed = Walking;
	PMotor.movement.maxBackwardsSpeed = Walking/2;
	PMotor.movement.maxSidewaysSpeed = Walking;
	if (Aiming)  
	//if aiming while walking
		{
		PMotor.movement.maxForwardSpeed = WalkAim;
		PMotor.movement.maxBackwardsSpeed = WalkAim/2;
		PMotor.movement.maxSidewaysSpeed = WalkAim;
		}
	}
else if (PlayerS==2 && BossC.isGrounded) 
//animation for sprinting, speed
	{
	Anim.animation["Sprint"].speed = CharacterMag/Sprinting;
    Anim.animation.CrossFade("Sprint", 0.2);
	PMotor.movement.maxForwardSpeed = Sprinting;
	PMotor.movement.maxBackwardsSpeed = Sprinting/2;
	PMotor.movement.maxSidewaysSpeed = Sprinting;
	}
else if (Crouch && BossC.isGrounded) 
//animation for crouching, speed
	{
	Anim.animation["Crouch"].speed = CharacterMag/Crouching;
    Anim.animation.CrossFade("Crouch", 0.2);
	PMotor.movement.maxForwardSpeed = Crouching;
	PMotor.movement.maxBackwardsSpeed = Crouching/2;
	PMotor.movement.maxSidewaysSpeed = Crouching;
	if (Aiming) 
	//if aiming while crouching
		{
		PMotor.movement.maxForwardSpeed = CrouchAim;
		PMotor.movement.maxBackwardsSpeed = CrouchAim - 0.5;
		PMotor.movement.maxSidewaysSpeed = CrouchAim;
		}
	}
else if (PlayerS==4 && BossC.isGrounded)
//animation for grounding, speed
	{
	Anim.animation["Ground"].speed = CharacterMag/Grounding;
    Anim.animation.CrossFade("Ground", 0.2);
	PMotor.movement.maxForwardSpeed = Grounding;
	PMotor.movement.maxBackwardsSpeed = Grounding/2;
	PMotor.movement.maxSidewaysSpeed = Grounding;
	}
	if (Aiming)  
	//if aiming while Grounding
		{
		PMotor.movement.maxForwardSpeed = GroundAim;
		PMotor.movement.maxBackwardsSpeed = GroundAim -0.3;
		PMotor.movement.maxSidewaysSpeed = GroundAim;
		}
if (Aiming) 
//animation for aiming, speed
	{
	Anim.animation["Aim"].speed = CharacterMag/Aiming;
    Anim.animation.CrossFade("Aim", 0.2);
	}
if (Shooting && BossC.isGrounded) 
//adjust for shooting, decrease speed
	{
	Anim.transform.rotation.y += 0.5;
	Anim.transform.position.y -= 0.03;
    //Anim.animation.CrossFade("Recoil", 0.2);
	PMotor.movement.maxForwardSpeed += WhenShooting;
	PMotor.movement.maxBackwardsSpeed += WhenShooting;
	PMotor.movement.maxSidewaysSpeed += WhenShooting;
	if (!Shooting) 
	//return back to normal once stopped shooting
		{
		Anim.transform.rotation.y -= 0.5;
		Anim.transform.position.y += 0.03;
		PMotor.movement.maxForwardSpeed -= WhenShooting;
		PMotor.movement.maxBackwardsSpeed -= WhenShooting;
		PMotor.movement.maxSidewaysSpeed -= WhenShooting;
		}
	}
if (Reloading)
 //animation for reloading, speed
	{
	Reloading=false;
    Anim.animation.CrossFade("Reload", 0.2);
	}
if (Jump && !BossC.isGrounded) 
//animation for jumping
	{
	Jump=false;
    JumpAnim.animation.Play("Jump");
	}
if (!Jump && BossC.isGrounded) 
//animation for landing
	{
	Jump=true;
	JumpAnim.animation.Play("Land");
	}

}

I am getting several Semicolon errors (I’ve read posts and it says that when this is said, the error is something else, but can’t find the errors/solutions. If someone could help me reoder the code so it would be correct, i’d appreciate it.

Regards,
Me4dinosaur

Line 58: You have the wrong bracket. It is { it should be }.

Line 91: You are missing a } bracket to finish off the last function.

Line 166-176: You never declared the “Walking” variable.

Line 227 & 236: You never declared the “Shooting” variable but you do have a “Shoot” variable. Either change Shooting to Shoot or add a new Shooting variable.

Line 246: You never declared the “Reloading” variable but you have a “Reload” variable. Either change Reloading to Reload or add a new Reloading variable.

After I fixed all those mistakes the errors went away. That doesn’t mean the code is going to work for sure, but you can now at least run the game to test it. Here is the working code:

var Crouching: float = 4;
var Sprinting: float = 10;
var Walking: float = 4;
var Grounding: float = 2.5;
var WhenShooting: float = -0.5;
var WalkAim: float = 4;
var CrouchAim: float = 2.5;
var GroundAim: float = 1.5;
//player control
var BossC: CharacterController;
var PlayerS: float;
var PMotor: CharacterMotor;
var Anim: GameObject;
var JumpAnim: GameObject;
//types of especial movement
var Jump: boolean = false;
var Crouch: boolean = false;
var Ground: boolean = false;
var Sprint: boolean = false;
var Reload: boolean = false;
var Aiming: boolean = false;
//for shooting
var CanShoot: boolean = false;
var Shoot: boolean = false;
var Mag: float = 32;
var Bullets: float;
var MaxAmmo: float = 256;
//extras
var CharacterMag;
//Player States = -1: long idle, 0: idle, 1: walk, 2: sprint, 3: crouch, 4: ground, 5:aim, 6: shoot, 7:reload
 
 
function Start () {
    PlayerS=0;
    Bullets=32;
 
}
 
function Update () {
    Player_State ();
    Player_Anims ();
    CharacterMag = BossC.velocity.magnitude;
    ReloadYes ();
    Is_Shooting ();
 
}
 
function ReloadYes () 
{
 
if (Bullets<=32 && Bullets >0 &&!Input.GetButton("Sprint") && BossC.isGrounded)
    {
    CanShoot=true;
    }
else if (Bullets==0)
    {
    CanShoot=false;
    Reload=true;
    }
else if (Bullets<32 && Bullets>0)
    {
    Reload=true;
    }
else if (Bullets==32)
    {
    Reload=false;
    }
else if (Reload && Input.GetButton("Reload") &&! Input.GetMouseButton(1) &&! Input.GetMouseButton(0) &&!Input.GetButton("Sprint") && BossC.isGrounded)
    {
    Reload=true;
    }
}
 
function Is_Shooting ()
 { 
 
    if (CanShoot)
        {
        if (Input.GetMouseButton(1))
            {
            Shoot=true;
            if (Input.GetMouseButtonUp(1))
                {
                Shoot=false;
                BroadcastMessage("Shoot", false, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    if (Shoot)
        {BroadcastMessage("Shoot", true, SendMessageOptions.DontRequireReceiver);
	}
 }
function Player_State () 
{ 
 
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") !=0) 
//If character moves
    {
    if (Input.GetButton("Sprint") &&! Input.GetMouseButton(1) &&! Input.GetMouseButton(0)) 
    //if character sprints
        {
        PlayerS=2;
        }
    else if (Input.GetMouseButton(0) &&! Input.GetButton("Sprint") && BossC.isGrounded) 
    //if character aims
        {
        Aiming=true;
        }
    else if (Input.GetButton('Crouch') &&! Input.GetButton("Sprint"))
     //if character crouches
        {
        Crouch=true;
        }
    else 
    //if character moves but does no special movement, just walks
        {
        PlayerS=1;
        }
    }
else if (Input.GetMouseButton(0) &&! Input.GetButton("Sprint"))  
//if character aims
    {
    Aiming=true;
    }
else if (Input.GetButton('Jump') && !BossC.isGrounded) 
//if character jumps
    {
    Jump=true;
    }
else if (Input.GetButton('Crouch')  && PlayerS&&! Input.GetButton("Sprint")) 
//if character crouches
    {
    Crouch=true;
    }
else
    {
    //if character stays idle for long
    if (Time.deltaTime>=10.0) 
        {
        PlayerS=-1;
        }
    else
        {
        //if character is not moving, idle
        PlayerS=0; 
 
        }
    }
 
}
function Player_Anims () 
{ 
 
if (PlayerS==0) 
//animation for player idle
    {
    PMotor.animation.CrossFade('Idle', 0.2);
    }
else if (PlayerS==-1 ) 
//animation for long player idle
    {
    PMotor.animation.CrossFade('LongIdle', 0.2);
    }
else if (PlayerS==1 && BossC.isGrounded) 
//animation for walking, speed
    {
    Anim.animation["Walk"].speed = CharacterMag/Walking;
    Anim.animation.CrossFade("Walk", 0.2);
    PMotor.movement.maxForwardSpeed = Walking;
    PMotor.movement.maxBackwardsSpeed = Walking/2;
    PMotor.movement.maxSidewaysSpeed = Walking;
    if (Aiming)  
    //if aiming while walking
        {
        PMotor.movement.maxForwardSpeed = WalkAim;
        PMotor.movement.maxBackwardsSpeed = WalkAim/2;
        PMotor.movement.maxSidewaysSpeed = WalkAim;
        }
    }
else if (PlayerS==2 && BossC.isGrounded) 
//animation for sprinting, speed
    {
    Anim.animation["Sprint"].speed = CharacterMag/Sprinting;
    Anim.animation.CrossFade("Sprint", 0.2);
    PMotor.movement.maxForwardSpeed = Sprinting;
    PMotor.movement.maxBackwardsSpeed = Sprinting/2;
    PMotor.movement.maxSidewaysSpeed = Sprinting;
    }
else if (Crouch && BossC.isGrounded) 
//animation for crouching, speed
    {
    Anim.animation["Crouch"].speed = CharacterMag/Crouching;
    Anim.animation.CrossFade("Crouch", 0.2);
    PMotor.movement.maxForwardSpeed = Crouching;
    PMotor.movement.maxBackwardsSpeed = Crouching/2;
    PMotor.movement.maxSidewaysSpeed = Crouching;
    if (Aiming) 
    //if aiming while crouching
        {
        PMotor.movement.maxForwardSpeed = CrouchAim;
        PMotor.movement.maxBackwardsSpeed = CrouchAim - 0.5;
        PMotor.movement.maxSidewaysSpeed = CrouchAim;
        }
    }
else if (PlayerS==4 && BossC.isGrounded)
//animation for grounding, speed
    {
    Anim.animation["Ground"].speed = CharacterMag/Grounding;
    Anim.animation.CrossFade("Ground", 0.2);
    PMotor.movement.maxForwardSpeed = Grounding;
    PMotor.movement.maxBackwardsSpeed = Grounding/2;
    PMotor.movement.maxSidewaysSpeed = Grounding;
    }
    if (Aiming)  
    //if aiming while Grounding
        {
        PMotor.movement.maxForwardSpeed = GroundAim;
        PMotor.movement.maxBackwardsSpeed = GroundAim -0.3;
        PMotor.movement.maxSidewaysSpeed = GroundAim;
        }
if (Aiming) 
//animation for aiming, speed
    {
    Anim.animation["Aim"].speed = CharacterMag/Aiming;
    Anim.animation.CrossFade("Aim", 0.2);
    }
if (Shoot && BossC.isGrounded) 
//adjust for shooting, decrease speed
    {
    Anim.transform.rotation.y += 0.5;
    Anim.transform.position.y -= 0.03;
    //Anim.animation.CrossFade("Recoil", 0.2);
    PMotor.movement.maxForwardSpeed += WhenShooting;
    PMotor.movement.maxBackwardsSpeed += WhenShooting;
    PMotor.movement.maxSidewaysSpeed += WhenShooting;
    if (!Shoot) 
    //return back to normal once stopped shooting
        {
        Anim.transform.rotation.y -= 0.5;
        Anim.transform.position.y += 0.03;
        PMotor.movement.maxForwardSpeed -= WhenShooting;
        PMotor.movement.maxBackwardsSpeed -= WhenShooting;
        PMotor.movement.maxSidewaysSpeed -= WhenShooting;
        }
    }
if (Reload)
 //animation for reloading, speed
    {
    Reload=false;
    Anim.animation.CrossFade("Reload", 0.2);
    }
if (Jump && !BossC.isGrounded) 
//animation for jumping
    {
    Jump=false;
    JumpAnim.animation.Play("Jump");
    }
if (!Jump && BossC.isGrounded) 
//animation for landing
    {
    Jump=true;
    JumpAnim.animation.Play("Land");
    }
 
}