Placing an object between 2 objects.
I want to have a empty gameobject between 2 fighters as a camera focus, but I can't get it to move.
using UnityEngine;
using System.Collections;
public class FocusCamera : MonoBehaviour {
public Vector3 Player1Pos = new Vector3(0,0,0);
public Vector3 Player2Pos = new Vector3(0,0,0);
public Vector3 center = new Vector3(0,0,0);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Player1Pos = GameObject.FindGameObjectWithTag("Player").transform.position;
Player2Pos = GameObject.FindGameObjectWithTag("Player2").transform.position;
Vector3 center = ((Player1Pos + Player2Pos)*0.5f);
transform.Translate(center,Space.World);
}
}
Comment
Best Answer
Answer by Quertie · May 01, 2016 at 03:25 PM
I suppose that by "move" you mean always keep in the middle between your two fighters?
What you can do is replace
transform.Translate(center, Space.World);by
transform.position = center;Assuming this script is the one attached to the empty between the fighters, it should work this way ;)
Hope this helps!