Hi,
I was hoping to prototype a game where the player would control a bit like a helicopter, in that you could stay grounded on the terrain, fly up, forwards, strafe left, right etc.
I followed a quick youtube video which was for moving a plane (see below). And the movement is sort of what I’m after, but I don’t want the player to always be moving forward, I want to only move forward when a button is pressed (to move forward and accelerate to a max speed while the button is held). And I would also want to be able to strafe up and down on the spot without any forward momentum. Also if hovering in the air, then staffing left and right would be handy to implement as well. I’m still quite new to Unity and coding so any help adapting the below (or how to go about starting over would be great). Until now I’ve mostly been playing around with JS/ Unity Script which I’m a bit more comfortable with and understand a bit more if it’s easier to do in that, but as this tutorial I watched was CS I don’t mind using that as I want to learn it anyway.
Thanks in advance.
using UnityEngine;
using System.Collections;
public class PlanePilot : MonoBehaviour {
public float speed = 50.0f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Vector3 moveCamTo = transform.position - transform.forward * 10.0f + Vector3.up * 3.0f;
float bias = 0.96f;
Camera.main.transform.position = Camera.main.transform.position * bias +
moveCamTo * (1.0f -bias);
Camera.main.transform.LookAt (transform.position + transform.forward * 30.0f);
transform.position += transform.forward * Time.deltaTime * speed;
speed -= transform.forward.y * Time.deltaTime * 50.0f;
if (speed < 10.0f) {
speed =10.0f;
}
if (speed > 75.0f) {
speed = 75.0f;
}
transform.Rotate (Input.GetAxis("Vertical"), 0.0f, -Input.GetAxis("Horizontal"));
float terrainHeight = Terrain.activeTerrain.SampleHeight (transform.position);
if (terrainHeight > transform.position.y){
transform.position = new Vector3 (transform.position.x,
terrainHeight,
transform.position.z);
}
}
}