How to add physics to flight simulator
Hi, I am currently in the process of creating my flight simulator project, very simple, but the main aim of it is to emulate the realistic feel of movement in response to the controls. I have decided to use an xbox controller as the main user controller instead of keys. My plane can fly, and has a camera attached to its front to give a first person perspective, but I have a problem with adding a realistic feel to it by physics (rigidbody), coding wise I'm quite lost in what to do.
using UnityEngine;
using System.Collections;
public class PlanePilot : MonoBehaviour {
public float speed = 90.0f;
private Rigidbody planeRigidbody;
// Use this for initialization
void Start () {
Debug.Log ("Plane pilot script added to: " + gameObject.name);
planeRigidbody = GetComponent <Rigidbody> ();
}
// Update is called once per frame
void Update () {
transform.position += transform.forward * Time.deltaTime * speed;
transform.Rotate (Input.GetAxis ("Vertical"), 0.0f, -Input.GetAxis ("Horizontal") );
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight (transform.position);
if (terrainHeightWhereWeAre > transform.position.y) {
transform.position = new Vector3 (transform.position.x,
terrainHeightWhereWeAre, transform.position.z);
}
}
Sorry for any confusion within the question, my code so far is very basic as you can see so any help would be perfect. Thanks.
-Andre
Answer by bzdur · May 25, 2017 at 02:53 PM
@ Ledgend132 You can't go "realistic" without realistic physics laws inside your code. Check out my little project https://forum.unity3d.com/threads/waldo-pepper-realistic-flight-sim.469752/ and feel free to ask any question.
Answer by adv40864 · Nov 20, 2018 at 02:09 PM
simple way to make drone simulation in 10 mins
you will easily understand the physics concept and easily can apply