Vampyr Engel
Member
Well? Can we use this?
[/CODE]
[/CODE]
Code:
using UnityEngine;
using System.Collections;
public class HoverMotor : MonoBehaviour {
public float speed = 90f;
public float turnSpeed = 5f;
public float hoverForce = 65f;
public float hoverHeight = 3.5f;
private float powerInput;
private float turnInput;
private Rigidbody carRigidbody;
void Awake ()
{
carRigidbody = GetComponent <Rigidbody>();
}
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;
carRigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
}
carRigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
carRigidbody.AddRelativeTorque(0f, turnInput * turnSpeed, 0f);
}
}
[CODE]//This Vehicle Information
Transform thisVehicle;
HoverMotor myHoverMotor; //Motor Script, this will be whatever your vehicle uses
HoverAudio myHoverAudio; //Motor Audio Script, this will be whatever your vehicle uses
GameObject myCamera ; //Camera for this vehicle
GameObject playerExitPosition; //Position to put the player on exiting vehicle
public GameObject myCanvas;//Basic control information
//This is the Player information
GameObject myPlayer;//UFPS Player game object
vp_FPController myController;//UFPS Player controller
vp_FPInput myInput;//UFPS Player Input
//State of this vehicle, if we are in the vehicle or not
bool InThisVehicle=false;
void Start ()
{
//Set references to everything
thisVehicle = this.GetComponent<Transform>();
myHoverMotor = thisVehicle.GetComponent<HoverMotor>();
myHoverAudio = thisVehicle.GetComponent<HoverAudio>();
myCamera = thisVehicle.GetComponentInChildren<Camera>().gameObject;
playerExitPosition = thisVehicle.FindChild("PlayerExitPosition").gameObject;
//turn off Vehicle scripts and camera on start
myHoverAudio.enabled=false;
myHoverMotor.enabled=false;
myCamera.SetActive(false);
if(myCanvas)
myCanvas.SetActive(false);
}
//Exit vehicle keyboard input. In fixed update so it doesn't move at computer speed
void FixedUpdate ()
{
if(InThisVehicle)
{
//Change the Input to whatever you want to use
if(Input.GetKeyDown(KeyCode.Z))
ExitVehicle();
}
}
public void ExitVehicle()
{
myPlayer.SetActive(true);//turn on the player
myController.SetPosition(playerExitPosition.transform.position);//move the player
myInput.enabled=true;//enable the player's input
myHoverMotor.enabled=false;//turn off vehicle stuff
myHoverAudio.enabled=false;//turn off vehicle stuff
myCamera.SetActive(false);//turn off vehicle stuff
InThisVehicle=false;//We aren't in the vehicle anymore
if(myCanvas)
myCanvas.SetActive(false);
}
public void EnterVehicle()
{
myPlayer.SetActive(false);//turn off the player
myHoverMotor.enabled=true;//turn on vehicle stuff
myHoverAudio.enabled=true;//turn on vehicle stuff
myCamera.SetActive(true);//turn on vehicle stuff
InThisVehicle=true;//We are in the vehicle now
if(myCanvas)
myCanvas.SetActive(true);
}
//Make sure your trigger collider is big enough for the player to interact
//Also, make sure the Exit position is outside the trigger area
void OnTriggerEnter(Collider other)
{
//if a player enters trigger and the player isn't already in the vehicle
//just in case there are multiple players
if(other.gameObject.tag=="Player"&&InThisVehicle==false)
{
myPlayer=other.gameObject;//Get the player
myController=myPlayer.GetComponent<vp_FPController>();//Get the controller
myInput=myPlayer.GetComponent<vp_FPInput>();//Get the input
EnterVehicle();//Run the EnterVehicle function
}
}
}
[/CODE]
Code:
using UnityEngine;
using System.Collections;
public class red_InteractFreeHelicopter : MonoBehaviour {
//This Vehicle Information
Transform thisVehicle;
csHellicopter myMotor; //Motor Script, this will be whatever your vehicle uses
AudioSource mySounds; //Sounds for the helicopter
public GameObject myCamera ; //Camera for this vehicle
GameObject playerExitPosition; //Position to put the player on exiting vehicle
public GameObject myCanvas;//Basic control information
//This is the Player information
GameObject myPlayer;//UFPS Player game object
vp_FPController myController;//UFPS Player controller
vp_FPInput myInput;//UFPS Player Input
//State of this vehicle, if we are in the vehicle or not
bool InThisVehicle=false;
void Start ()
{
//Set references to everything
thisVehicle = this.GetComponent<Transform>();
myMotor = thisVehicle.GetComponent<csHellicopter>();
// myCamera = thisVehicle.GetComponentInChildren<Camera>().gameObject;
playerExitPosition = thisVehicle.FindChild("PlayerExitPosition").gameObject;
mySounds=thisVehicle.GetComponent<AudioSource>();
//turn off Vehicle scripts and camera on start
myMotor.enabled=false;
myCamera.SetActive(false);
mySounds.enabled=false;
if(myCanvas)
myCanvas.SetActive(false);
}
//Exit vehicle keyboard input. In fixed update so it doesn't move at computer speed
void FixedUpdate ()
{
if(InThisVehicle)
{
//Change the Input to whatever you want to use
if(Input.GetKeyDown(KeyCode.Z))
ExitVehicle();
}
}
public void ExitVehicle()
{
myPlayer.SetActive(true);//turn on the player
myController.SetPosition(playerExitPosition.transform.position);//move the player
myInput.enabled=true;//enable the player's input
myMotor.enabled=false;//turn off vehicle stuff
mySounds.enabled=false;
myCamera.SetActive(false);//turn off vehicle stuff
InThisVehicle=false;//We aren't in the vehicle anymore
if(myCanvas)
myCanvas.SetActive(false);
}
public void EnterVehicle()
{
myPlayer.SetActive(false);//turn off the player
myMotor.enabled=true;//turn on vehicle stuff
mySounds.enabled=true;
myCamera.SetActive(true);//turn on vehicle stuff
InThisVehicle=true;//We are in the vehicle now
if(myCanvas)
myCanvas.SetActive(true);
}
//Make sure your trigger collider is big enough for the player to interact
//Also, make sure the Exit position is outside the trigger area
void OnTriggerEnter(Collider other)
{
//if a player enters trigger and the player isn't already in the vehicle
//just in case there are multiple players
if(other.gameObject.tag=="Player"&&InThisVehicle==false)
{
myPlayer=other.gameObject;//Get the player
myController=myPlayer.GetComponent<vp_FPController>();//Get the controller
myInput=myPlayer.GetComponent<vp_FPInput>();//Get the input
EnterVehicle();//Run the EnterVehicle function
}
}
}