I was hoping to use the code from an old project for the camera.
I took the Start and LateUpdate from this old class, and merged it into UFE's camera script
using UnityEngine;
using System.Collections;
public class NewCam : MonoBehaviour
{
Transform P1Trans;
Transform P2Trans;
public float distScale = 3.0f;
void Start()
{
GameObject P1 = GameObject.FindGameObjectWithTag("Fighter1");
GameObject P2 = GameObject.FindGameObjectWithTag("Fighter2");
Transform[] allChildren1 = P1.GetComponentsInChildren<Transform>();
Transform[] allChildren2 = P2.GetComponentsInChildren<Transform>();
foreach (Transform child1 in allChildren1)
{
if (child1.name == "camPointer")
{
P1Trans = child1;
}
}
foreach (Transform child2 in allChildren2)
{
if (child2.name == "camPointer")
{
P2Trans = child2;
}
}
}
void LateUpdate()
{
Physics.IgnoreLayerCollision(8, 9, true);
Vector3 target = (P1Trans.position - P2Trans.position);
Vector3 Perpendicular = Vector3.Cross(target, Vector3.up);
Vector3 midPoint = (P1Trans.position + P2Trans.position) * 0.5f;
float dist = Vector3.Distance(P1Trans.position, P2Trans.position);
if (rigidbody.position != midPoint + Perpendicular.normalized * dist * distScale)
{
rigidbody.velocity = (midPoint + Perpendicular.normalized * dist * distScale) - rigidbody.position;
}
else
{
rigidbody.velocity = new Vector3(0, 0, 0);
}
camera.transform.LookAt(midPoint);
}
}
I'm having trouble with the camPointer objects, which are empty objects added to the character prefabs, and set at head height. These are what I used before to set the camera height.
Vector3 target = (P1Trans.position - P2Trans.position);
is throwing the error "Object reference not set to an instance of an object". I'm not sure why, but UFE seems to struggle with this. I used a rigidbody on the camera previously, because as you will have walls in a 3d arena fighter, I needed the camera to stay inside them.
If anyone can help, we can hopefully move on to the next issue.