forzabo
Member
I've successfully created a simple integration for Edy's Vehicle Physics for Opsive UFPS/ FPC.
I wrestled around a good bit with Redhawk's EVP integration but ran into several issues and couldn't get it to work. For my needs I really don't need the character to do anything other than be able to drive the vehicle (e.g. the character doesn't need to look around or shoot while driving) so really all I wanted was a seamless transistion from the FPC to EVP first-person driving view.
That said, I got a lot of ideas and borrowed much from Redhawk's scripts. I recommend people watch his video and check out his scripts for ideas on how to get these things to work.
video here -- version 1
https://www.opsive.com/forum/index.php?threads/edys-vehicle-physics.720/
version 2 here
Ok, so my approach is, as stated, quite simplistic and involves some redundancies, but it seems to work really well. Basically I start with a standard Opsive FPC scene implementation, with the character rig, cameras, game manager, UI canvas etc all out of the Opsive box so to speak. For the car setup I copy everything from the EVP demo scene, including the camera with its Vehicle Camera Controller. I changed the mode of the VehicleCameraController to AttachTo in order to get the first person, driver's eye view. The vehicle gets a dummy driver (more on that below) and the whole idea is that when the scene starts, the EVP stuff is dormant until the ability is activated, at which time the Opsive stuff is disabled, the character is hidden and the EVP stuff, including camera, takes over. When the ability stops, the process is reversed.
At the top level of each vehicle gameobject hierarchy (i.e. the gameobject with all of the EVP components), I added this script. It's mostly responsible for sniffing the Ability End player input and animating the driver's feet. There are also placeholders for detecting the vehicle's speed and whether it is going forward or reverse and whether it's accelerating.(these hooks may already be avaible somewhere in the EVP scripts, so this might be really hacky but it works for what I needed) EDIT-- EVP's vehicle controller exposes a speed variable so that can simply be polled instead of recalculating velocity:
Per Redhawk's EVP integration, I added a game object to the vehicle hierachy with a box collider trigger component to act as the ability trigger. This also receives an Object Identifier component (from Opsive) with an arbritary ID number assignment to be used by the ability:
Again, like Redhawk I have added empty gameobjects to the the car to act as IK targets for the character rig. The targets for the hand are children of the steering wheel transform.
(to be continued in next post)
I wrestled around a good bit with Redhawk's EVP integration but ran into several issues and couldn't get it to work. For my needs I really don't need the character to do anything other than be able to drive the vehicle (e.g. the character doesn't need to look around or shoot while driving) so really all I wanted was a seamless transistion from the FPC to EVP first-person driving view.
That said, I got a lot of ideas and borrowed much from Redhawk's scripts. I recommend people watch his video and check out his scripts for ideas on how to get these things to work.
video here -- version 1
https://www.opsive.com/forum/index.php?threads/edys-vehicle-physics.720/
version 2 here
Opsive and Edy’s Vehicle Physics (EVP)
Version 1 of Third Person Controller (Ultimate Character Controller) and Edy’s Vehicle Physics Integration. As I only have the Third Person piece, I do not know how this will work with the Fi…
redhwk.wordpress.com
Ok, so my approach is, as stated, quite simplistic and involves some redundancies, but it seems to work really well. Basically I start with a standard Opsive FPC scene implementation, with the character rig, cameras, game manager, UI canvas etc all out of the Opsive box so to speak. For the car setup I copy everything from the EVP demo scene, including the camera with its Vehicle Camera Controller. I changed the mode of the VehicleCameraController to AttachTo in order to get the first person, driver's eye view. The vehicle gets a dummy driver (more on that below) and the whole idea is that when the scene starts, the EVP stuff is dormant until the ability is activated, at which time the Opsive stuff is disabled, the character is hidden and the EVP stuff, including camera, takes over. When the ability stops, the process is reversed.
At the top level of each vehicle gameobject hierarchy (i.e. the gameobject with all of the EVP components), I added this script. It's mostly responsible for sniffing the Ability End player input and animating the driver's feet. There are also placeholders for detecting the vehicle's speed and whether it is going forward or reverse and whether it's accelerating.
Code:
using System.Collections.Generic;
using UnityEngine;
using EVP;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(VehicleStandardInput))]
[RequireComponent(typeof(VehicleController))]
[RequireComponent(typeof(VehicleAudio))]
public class EVP_Vehicle : MonoBehaviour
{
public enum State
{
stopped,
forward,
reverse,
brake
}
public State state = State.stopped;
[Tooltip ("Rigged Driver character")]
public GameObject m_Driver;
[Tooltip ("Game Object with EVP Camera Controller")]
public GameObject m_VehicleCameraGO;
// Edy's Vehicle Physics
VehicleStandardInput m_VehicleStandardInput;
VehicleController m_VehicleController;
VehicleAudio m_VehicleAudio;
Rigidbody m_Rigidbody;
// copies of IK targets to use with foot animation
Transform m_LeftFootTarget;
Transform m_RightFootTarget;
/// <summary>
/// Initialization.
/// </summary>
void Start()
{
//Disable camera, listener, and cam controller used by EVP
m_VehicleCameraGO.SetActive(false);
//Hide dummy driver
m_Driver.SetActive(false);
//Get EVP Component references
m_VehicleStandardInput = this.GetComponent<VehicleStandardInput>();
m_VehicleController = this.GetComponent<VehicleController>();
m_VehicleAudio = this.GetComponent<VehicleAudio>();
m_Rigidbody = gameObject.GetComponent<Rigidbody>();
//obtain references to foot IK targets
m_LeftFootTarget = m_Driver.GetComponent<EVP_Driver_Animation>().m_LeftFootTarget;
m_RightFootTarget = m_Driver.GetComponent<EVP_Driver_Animation>().m_RightFootTarget;
//Disable EVP input and audio
m_VehicleStandardInput.enabled = false;
m_VehicleAudio.enabled = false;
// Make sure the Vehicle doesn't move around
m_VehicleController.throttleInput = 0.0f;
m_VehicleController.brakeInput = 1.0f;
//ignore updates while vehicle is not in use.
enabled = false;
}
private bool action = false; //bool flag to avoid multiple action events
private float oldVelocity = 0;
/// <summary>
/// Poll for end ability input and update character animation based on input and velocity.
/// Update is not enabled until ability starts.
/// </summary>
private void Update()
{
// hack poll for action key to stop ability
if(Input.GetAxis("Action") > 0 & !action)
{
action = true;
EVP_DriveAbility ability = Globals.instance.uCL.GetAbility<EVP_DriveAbility>();
Globals.instance.uCL.TryStopAbility(ability);
}
else if (action && Input.GetAxis("Action") < Mathf.Epsilon)
{
action = false;
}
// The following uses the forward velocity of the vehicle along with the input values to compute
// simple IK target transformations for the drivers feet (e.g. mashing pedals)
// NOTE (edit): this next line of code is unneccessary -- can use m_VehicleController.speed instead
float velocity = transform.InverseTransformDirection(m_Rigidbody.velocity).z;
if (Mathf.Abs(velocity) < Mathf.Epsilon)
{
//car is stopped
state = State.stopped;
}
else if(velocity > 0)
{
state = State.forward;
if (velocity >= oldVelocity)
{
//car is accelerating fwd -- do something here, maybe
}
else
{
//car is decelerating/braking
}
}
else
{
state = State.reverse;
if (velocity <= oldVelocity)
{
//car is accelerating in reverse
}
else
{
//car is decelerating, in reverse
}
}
oldVelocity = velocity;
//animate feet in response to gas/brake inputs
float gas_brake_input = Input.GetAxis("Vertical");
if (Mathf.Abs(gas_brake_input) > Mathf.Epsilon)
{
if (state == State.stopped || state == State.forward)
{
m_RightFootTarget.localEulerAngles = new Vector3(Mathf.Clamp(45.0f * gas_brake_input - 45.0f, -45, 0), 0, 0);
m_LeftFootTarget.localEulerAngles = new Vector3(Mathf.Clamp(-(45.0f * gas_brake_input + 45.0f), -45, 0), 0, 0);
} else
{
m_LeftFootTarget.localEulerAngles = new Vector3(Mathf.Clamp(45.0f * gas_brake_input - 45.0f, -45, 0), 0, 0);
m_RightFootTarget.localEulerAngles = new Vector3(Mathf.Clamp(-(45.0f * gas_brake_input + 45.0f), -45, 0), 0, 0);
}
}
}
}
Per Redhawk's EVP integration, I added a game object to the vehicle hierachy with a box collider trigger component to act as the ability trigger. This also receives an Object Identifier component (from Opsive) with an arbritary ID number assignment to be used by the ability:
Again, like Redhawk I have added empty gameobjects to the the car to act as IK targets for the character rig. The targets for the hand are children of the steering wheel transform.
(to be continued in next post)
Attachments
Last edited: