How do I make my CharacterController Jump and Crouch?

Hello! I’m making an FPS in Unity, and I wanted to know how to make my CharacterController to jump and crouch? I Googled it for some time, but all I got was info on how to do it with the default Chracter Controller package, but I’m not actually using it, I’m using my own.

I thought about using:

transform.Translate(Vector3.up * jumpHeight)

but it didn’t work. My player would go up and just stay there. :frowning:
Here’s my code for reference, thanks in advance!

using UnityEngine;
using System.Collections;

public class FPSController : MonoBehaviour {

	public float moveSpeed;
	private float sprintSpeed;

	public float mouseSpeed;
	private float lastMouseSpeed;	
	private float upDownMax = 70f;
	float upDown = 0f;

	public static bool jumping = false;
	public float jumpHeight;

	public CharacterController player;
	public Rigidbody body;
	public Camera playerview;

	void Start() {
		lastMouseSpeed = mouseSpeed;
		sprintSpeed = moveSpeed * 5f; // Should be 2.5f;
		player = GetComponent<CharacterController>();
	}

	void Update() {
		float leftRight = Input.GetAxis("MouseX") * mouseSpeed;
		transform.Rotate(0, leftRight, 0);

		upDown -= Input.GetAxis("MouseY") * mouseSpeed;
		upDown = Mathf.Clamp(upDown, -upDownMax, upDownMax);
		playerview.transform.localRotation = Quaternion.Euler(upDown, 0, 0);

		float forward = Input.GetAxis("Forward") * moveSpeed;
		float side = Input.GetAxis("Side") * moveSpeed;

		Vector3 movement = new Vector3(side, 0, forward);
		movement = transform.rotation * movement;

		if (Input.GetButtonDown("Jump")) {
			transform.Translate(Vector3.up * jumpHeight);
			jumping = true;
		}

		if (Input.GetButton("Sprint")) {
			moveSpeed = sprintSpeed;
		} else {
			moveSpeed = sprintSpeed / 5f; // Should be 2.5f;
		}

		movement.y -= 10f * Time.deltaTime;
		player.Move(movement * Time.deltaTime);
	}

	public void setMouseSpeed(float mouseSpeed) {
		this.mouseSpeed = mouseSpeed;
	}

	public float getLastMouseSpeed() {
		return lastMouseSpeed;
	}
}

Take a look at this thread for adding jumping and running:

For jumping (comprehensive and includes falling damage, but you really only need the rigidbody.velocity line):

using UnityEngine;
using System.Collections;

public class Jump : MonoBehaviour
{
	//jumping stuff
	public float jumpheight = 150f;
	private bool grounded;
	public LayerMask groundLayer;

	//falling damage stuff
	private bool falling;
	private float fallStartLevel;
	public float fallingDamageThreshold = 0.5f;


	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {
		Ray groundRay = new Ray(transform.position, transform.position - transform.up * 1.0f);
		RaycastHit groundHit;

		if(Physics.Linecast(transform.position + transform.up * 0.15f, transform.position - transform.up * 0.15f, groundLayer) == true) {
		//if (Physics.Raycast(groundRay, out groundHit, Mathf.Infinity, groundLayer) == true) {
			grounded = true;
		}
		else {
			grounded = false;
		}

	}


	void FixedUpdate() {

		if(Input.GetKeyDown(KeyCode.Space)) {
			if(grounded == true) {
				//rigidbody.AddForce(Vector3.up * jumpheight);
				rigidbody.velocity = new Vector3(0, jumpheight / 50, 0);
				return;
			}
		}


		if(grounded == false)
		{
			if (falling == false) 
			{
				falling = true;
				fallStartLevel = transform.position.y;
			}
			if(transform.position.y > fallStartLevel) {
				fallStartLevel = transform.position.y;
			}

		}
		else {
			if (falling == true) {
				falling = false;
				
				if (transform.position.y < fallStartLevel - fallingDamageThreshold) {
					ApplyFallingDamage (fallStartLevel - transform.position.y);
				}
			}
		}
	}

	void ApplyFallingDamage (float fallDistance) {

		float fallingDamage = fallDistance * 30;
		print ("Ouch! Taken " + fallingDamage + " falling damage!");


	}	
	
	

}