Flying Controls in Unity - Tutorial - gamenightuiuc.com

Flying Controls in Unity – Tutorial

gamesplusjames
Views: 47791
Like: 1371
Learn how to create flying controls perfect for space flight games, or for flying airplanes!

Download the starter files for the project at

Wishlist ‘Scoot Kaboom and the Tomb of Doom’ right now at !

Get my new Udemy course ‘Learn To Create A First Person Shooter With Unity & C#’ at

Don’t forget to hit that like button and if you’d like to see more gaming goodness then subscribe for more!

Join the discord community at

Follow @gamesplusjames on twitter at

Support the show by pledging at

#gamedev #madewithunity

110 Comments

  1. Does anybody have a clue about what do if I want the movement, based on the mouse cursor (beginning at 14.00), to be much more sensitive? I tried to increase the lookratespeed, but it didn't have any effect

  2. Hiya, new subscriber so i followed the whole steps and all and it works perfectly i love the spaceship and the truster glow. I have a question how can i add some details in the background?

    Example: I made a custom BG in blender

    how do i add the blender file in order to merge in the background?

  3. For those wondering how to add collisions, I did it like this:
    *Add a Rigidbody component, then replace:
    transform.position += transform.forward * activeForwardSpeed * Time.deltaTime;
    transform.position += (transform.right * activeStrafeSpeed * Time.deltaTime) + (transform.up * activeHoverSpeed * Time.deltaTime);
    *with this (in a Fixed Update):
    Vector3 forward = transform.forward * activeForwardSpeed * Time.fixedDeltaTime;
    Vector3 strafe = transform.right * activeStrafeSpeed * Time.fixedDeltaTime;
    Vector3 hover = transform.up * activeHoverSpeed * Time.fixedDeltaTime;

    Vector3 movement = forward + strafe + hover;

    gameObject.GetComponent<Rigidbody>().MovePosition(transform.position + movement);
    Of course, you could reference the Rigidbody, so it could be anywhere in the scene, but this should work nonetheless. Hopes this helps.

  4. How do you create the actual space environment?

  5. ummm can you help the code isn't working

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class ShipController : MonoBehaviour

    {

    public float forwardsSpeed = 25f, strafeSpeed = 7.5f, hoverSpeed = 5f

    private float activeForwardsSpeed, activeStrafeSpeed, activeHoverSpeed;

    // Start is called before the first frame update

    void Start()

    {

    }

    // Update is called once per frame

    void Update()

    {

    activeForwardsSpeed = input.GetAxisRaw("Vertical") * forwardsSpeed;

    activeStrafeSpeed = input.GetAxisRaw("Horizontal") * strafeSpeed;

    activeHoverSpeed = input.GetAxisRaw("Hover") * hoverSpeed;

    transform.position += transform.forward * activeForwardsSpeed * Time.deltaTime;

    }

    }

  6. Can anyone help? Time is not being recognised when i put it in (not going green) in visual studio

  7. Hey, mate, why not using new input system?

  8. Excellent Tutorial btw… really appreciate it. Thank you. Will be hunting for a good follow camera tutorial next and a good shooting tutorial.

  9. error CS1503: Argument 3: cannot convert from 'UnityEngine.Space' to 'float'

  10. Could someone please help me? When I run the game then my ship just launches forward, as if I am holding down "w". This also happens with other movement scripts for me. I tried on both 2019.4.9f1 Personal and the 2020.3.2f1 versions. I have been cracking my mind for several days at this point.

  11. mine rolls to the right when I move my mouse up, and rolls left when I move my mouse down. help

  12. how can i set bounds when looking around? so for example if i look down, the player wont just keep spinning, it would just stop. same with all the other axis's. also one more thing, whenever i look in a direction, its inverted

  13. CS7036 "There is no argument given that corresponds to the required formal parameter 't' of 'Mathf.Lerp(float, float, float)

    Same error for all Mathf lines. I even tried copying the code in the video 100% identically and it throws the same error.

    Can someone please help me out? I'm at a loss on this one and really wanted to get these controls figured out.

  14. Thank you for creating a flight system tutorial that actually addresses Lerp! And with such a simple setup!
    You must make the other coding channels jealous. ;P

  15. Hi, I got an error saying "error CSO266: cannot implicity convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)" can you please help me?

  16. when i try to play it cannot move forward but the plane still move rightly along with the cursor , help 🙁

  17. dude the font is so small and hard to read on ur scripting. Great script but hurts my eyes trying to learn

  18. i know this is kind of a late reaction but how do i make cursor deadzones in the middle of the screen?

  19. Great tutorial. only one question. is there a way to lock the Z rotation? becouse if you keep flying a bit you end up upside down or tilted. EDIT: I fixed it by adding this at the end of the update:

    if (transform.localEulerAngles.z != 0)

    {

    float rotX = transform.localEulerAngles.x;

    float rotY = transform.localEulerAngles.y;

    transform.localEulerAngles = new Vector3(rotX, rotY, 0);

    }

  20. If someone facing problems with the COLLISION just

    *Add a Rigidbody component, then replace:

    transform.position += transform.forward * activeForwardSpeed * Time.deltaTime;

    transform.position += (transform.right * activeStrafeSpeed * Time.deltaTime) + (transform.up * activeHoverSpeed * Time.deltaTime);

    *with this (in a Fixed Update):
    Vector3 forward = transform.forward * activeForwardSpeed;

    Vector3 strafe = transform.right * activeStrafeSpeed;

    Vector3 hover = transform.up * activeHoverSpeed;

    Vector3 movement = forward + strafe + hover;

    gameObject.GetComponent<Rigidbody>().AddForce(movement);

    Hope it helps 😉

  21. Works great, however when colliding with another object, the mouse controls become "uncentered"… like, the center for the mouse moves when the ship is knocked off its current rotation by another rigid body. Does anyone have a fix for this?

  22. The A and D keys are moving me up and down. The ctrl and space keys are moving me left to right! Help pls

  23. Holy hell, this tutorial was a life saver! Been struggling trying to get some of the Mathf.Lerp code to work from another tutorial, because they had some of the syntax wrong…

    May swap some of the controls around so that hover and strafe are excluded, and mousing to the left/right give roll instead. That is, if I dont break the script first! 😀

  24. I'm not sure if you can help, but is it possible to make the ship roll by follow the cursor? Like with War Thunder aircrafts.

  25. The tutorial works great and is exactly what I need, but as a beginner I had a hard time understanding whats actually going on in the code. I just have to learn more I guess

    Edit: It dosent work that well with collision though. That seems like a big oversight

  26. When I hit play I have to click the mouse for it to stay steady. If I don't the camera rotates like crazy. Anyone have a fix?

  27. Excellent guide. My hello world of Unity is a crude solar system. Exploring is a debugging tool, and learning how input works compared to my desktop background.

  28. OMG YOU SAVE MY LIFE , FORR THE ETERNITY I WILL SAY THAN YOU !!!!!!!!!!!

  29. any way to make the rotation work with a controller?

  30. Hey there, does anyone know how i can change the q and e roll to follow the mouse instead of keyboard input?

  31. 00:32 Am i the only one that heard "You can do so by f**king them in the link in the description"? HAHAHA

  32. Need help with: if(player is moving in world space z or -z direction){do other code here to move UI Icon direction of x direction as the player is being pushed in the x direction always and UI Icon must show this when player is facing in either z or -z world space ditection movement the icon either points right or left depending on the player z movement} The code inside the brackets is fine but the if( player is moving in z or -z world space) I can not figure out 3 weeks later. Alll the best from 🏴󠁧󠁢󠁳󠁣󠁴󠁿👨‍💻 👍

  33. works great till the object collides with something then it starts moving on it's own.

    Edit: I modified the code to use velocity instead, and now it works perfectly for me. I very much appreciate the code you posted, thankyou.

  34. Great work! you could treat the accel as thrusters and simulate the dynamics with a simple finite difference aproximation. For x-axis: xNew = activeForceX/shipMass +2*xActive-xOld. The same for y and z axes.

  35. Gotta say this tutorial is amazing but one thing is really stumping me.
    Is there any way to add say a circle or just an area in the middle of the screen where the mouse doesn’t effect the ship until it leaves that area? Just wondering since this would be really helpful and i got absolutely no clue how to do it.
    Thank you!

  36. What works for one game doesn't mean it will work for another. It's still a mess for me even when I did everything step by step.

Leave a Reply

Your email address will not be published.