How to make character movement track users head rotation
Below is the code I am using to track the player but the direction and rotation is not working and I don't know exactly why. Any help would be highly appreciated!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTracking : MonoBehaviour {
public GameObject ScatterplotCube;
public GameObject User_HTCVive;
public GameObject MiniMapcube;
public GameObject Character;
// Use this for initialization
void Start () {
//Vector3 repositionMinimap = MiniMapcube.transform.localPosition + new Vector3(0, 0.3f, 0.3f);
//MiniMapcube.transform.localPosition = repositionMinimap;
}
// Update is called once per frame
private void Update()
{
}
void FixedUpdate() {
// Position
Vector3 VecPosition = ScatterplotCube.transform.InverseTransformPoint(User_HTCVive.transform.position);
//Debug.Log(VecPosition);
Vector3 tp = MiniMapcube.transform.localPosition + (VecPosition);
transform.localPosition = tp;
// Rotation
Vector3 VecRotation = ScatterplotCube.transform.InverseTransformDirection(Vector3.zero);
Vector3 tr = MiniMapcube.transform.rotation.eulerAngles + VecRotation;
transform.rotation = Quaternion.Euler(VecRotation);
}
}
Good day.
I dont understand what you mean by "traking". And what you mean with direction and rotation. The Camera? The character is not controlled by you? Why you need to "track" ?
It will be great if you help us to understand exactly what is happening and what you want to get.
$$anonymous$$ake some Paint draws for example, to easy transmit this info, And i see you have a variable called User_HTCVive. You should say in the title and as a tag, that is HTCVive project. This wil help HTC experts to see your post.
Bye!
@tormentoarmagedoom Good day. Thank you for your reply!
I have a character inside a cube and the character moves when the user with the htc device in the head moves, but my problem is that when the user rotates it isn't tracking that rotation correctly.