How do I give the player free flight?

What I would like to do is give my player the option of free flight.

So for example, if I were to press the space bar twice(once to jump and twice in the air to initiate flight) the player model would fly.

To go higher the player would press and hold the left mouse button and to go lower they would hold the right mouse button.

I’m making a test game and I would really like to implement this feature, I’m using C# script and would appreciate any help or advice on the topic :slight_smile:

I’ve made the model, I’m currently working on it’s animations so I’m hoping by the time I’m done that someone would have posted an answer to help with this. If it helps, I’m using a 3D game, not 2D. If someone could post an example script, I would greatly appreciate it.

I’m pretty new to Unity and I still consider myself pretty inexperienced so if there’s any special options or such, providing screenshots would be an incredible bonus.

I forgot to add that I’m using the a basic script that I learned from watching a tutorial:

using UnityEngine;
using System.Collections;

public class PlayerGame : MonoBehaviour
{

    private Animator anim;

    // Use this for initialization
    void Start()
    {
        anim = gameObject.GetComponentInChildren<Animator>();
    }

    // Update is called once per frame
    void Update()

    {

        if (Input.GetKey("w"))
        {
            anim.SetInteger("AnimPar", 1);
        }
        else
        {
            anim.SetInteger("AnimPar", 0);
        }

        if (Input.GetKeyDown("space"))
        {
            anim.SetInteger("Jump", 2);
        }
        else
        {
            anim.SetInteger("Jump", 0);
        }

        if (Input.GetKey("left shift"))
        {
            anim.SetInteger("Run", 3);
        }
        else
        {
            anim.SetInteger("Run", 0);
        }

    }
}

I think I have to edit something along the Y axis but again I’m very new to this and I don’t know exactly how to do this. I’ve tried looking up tutorials for this but haven’t had much luck as they don’t usually work and just give me lots of errors, despite mimicking the instructor’s guide down to the letter.

@AlwaysSunny I tried a new code(which I think is better) but I’m still running into the same problem of not being able to fly.

using UnityEngine;
using System.Collections;

public class KalusBeta : MonoBehaviour
{
	private CharacterController controller;

	private float verticalVelocity;
	private float gravity = 14.0f;
	private float jumpForce = 10.0f;

	private void Start()
	{
		controller = GetComponent<CharacterController>();
	}

	private void Update()
	{
		if (controller.isGrounded) 
		{
			verticalVelocity = -gravity * Time.deltaTime;
			if (Input.GetKeyDown (KeyCode.Space)) 
			{
				verticalVelocity = jumpForce;
			}
		}  
		else 
		{
			verticalVelocity -= gravity * Time.deltaTime;
		}	

		Vector3 moveVector = Vector3.zero;
		moveVector.x = Input.GetAxis("Vertical") * +40.0f;
		moveVector.y = verticalVelocity;
		moveVector.z = Input.GetAxis("Horizontal") * -40.0f;
		controller.Move (moveVector * Time.deltaTime);

		if(Input.GetKey("Space"))
			{
				transform.Translate(0,+0.6f,0);
			}
				

	}
}

(Also thank you so much for pointing out the 101010 button, I feel like a dork for not noticing it earlier XD)

I tried adding + to the Y translation but again it doesn’t seem to do anything other then make the player jump. I have gravity on(which from what I’ve seen in tutorials, should make the player sink when in the air but not stop flight)

I have also tried If(Input.GetKey(“Space”)) and If(Input.GetKey(“Jump”)) but none seem affective either P: