Getting started to make an aircraft that can take off and be controlled using WASD keyboard buttons on Unity



In this video I am trying to make an airplane that can take off and be controlled using my WASD buttons on my keyboard.

It is somehow an experiment and also a tutorial, so please don’t be mad if I made mistakes in this video before finally I made my way to fix any problem along the way.

Check out this TNAirPlane C# script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TNAirPlane : MonoBehaviour
{
	
	public float thrust = 10f;
	public float topspeed = 20f;
	public float defaultLift = 1f;
	
	Rigidbody rb;
	
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
		rb.velocity = transform.forward * thrust;
		transform.Rotate(defaultLift,0,0);
		
		if(Input.GetKey(KeyCode.W)){
			transform.Rotate(.5f,0,0);
		}
		if(Input.GetKey(KeyCode.S)){
			transform.Rotate(-.5f,0,0);
		}
		if(Input.GetKey(KeyCode.A)){
			transform.Rotate(0,0,.5f);
		}
		if(Input.GetKey(KeyCode.D)){
			transform.Rotate(0,0,-.5f);
		}
		
    }
}

Check out the complete parts of this tutorial here: https://thirteenov.ciihuy.com/making-an-airplane-game-from-scratch-in-unity/

loading...

Leave a Reply

Your email address will not be published.