Okay, so I have the first person controller and the code set up and ready for a sort of hovering vehicle.
using UnityEngine;
using System.Collections;
public class HoverMotor : MonoBehaviour {
public float speed = 90f;
public float turnspeed = 5f;
public float hoverforce = 65f;
public float hoverheight = 1f;
public bool canride = false;
private float powerInput;
private float turnInput;
private Rigidbody carigidbody;
// Use this for initialization
void Awake () {
carigidbody = GetComponent <Rigidbody>();
}
// Update is called once per frame
void Update () {
powerInput = Input.GetAxis ("Vertical");
turnInput = Input.GetAxis ("Horizontal");
}
void FixedUpdate()
{
Ray ray = new Ray (transform.position, -transform.up);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, hoverheight))
{
float proportionalheight = (hoverheight - hit.distance) / hoverheight;
Vector3 appliedhoverforce = Vector3.up * proportionalheight * hoverforce;
carigidbody.AddForce(appliedhoverforce, ForceMode.Acceleration);
}
carigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
carigidbody.AddRelativeTorque(0f, turnInput * turnspeed, 0f);
}
}
Fairly simple stuff. However, my player obviously slips and slides around on it as I try and drive it. So I have a few questions.
One, how do I set up a trigger and/or button that will deactivate whether or not my controls are moving this thing unless the player is on it or has clicked something that would signify the wheel.
Had do I lock and unlock a player in position when they click on said wheel or enter said craft.
Please, any responses to this conundrum will be heavily appreciated. I think that this could end up having some nice effects when it’s done.