Hi everyone !
I wish someone could help me because if not i’m stuck forever
I’m making a Vr App and i’ve some probleme for the rotation of my object :
I’ve made a capsule for my character and I use the CardboardAdapter prefab.
I didn’t made the capsule a child or a parent of the camera because i never succeed to update the rotation of the Capsule(which have the script making going forward) by those of the camera and so
i couldn’t going where i was looking.
So i have two distinct object :
-
the MainCamera (with CardboardAdapter as a child)
-
and my Capsule
I’ve wrote those two scripts :
-
One in JS which make the capsule taking the rotation.y of the Camera)
-
One in C# which make the Camera following the capsule transform.position with an offset
But i have some problemes it doesn’t work for all the angles so i told myself i juste have to log the rotation.y of both objects on the game screen in realtime for seeing what’s happening but it always log the same so there is not the problem here And when i make the rotation of the CardboardAdapter differently before making the simulation, it make the capsule following the rotation of the CardboardAdapter more and more slowly( for example MAin Camera set to 180° and capsule to 50°, i launch simulation and directly the capsule goes to 175 and very slowly goes to 180°)
So i hope someone can understand my so good english (Sorry I’m French)
There are the scripts :
/////
the JS script attached to the caps
var rb : Rigidbody;
var cameraRotat : Transform ;
var capsRotat : Transform;
var Adapt : GameObject;
function Start()
{
rb = GetComponent.<Rigidbody> ();
}
function FixedUpdate()
{
capsRotat = GetComponent.<Transform> ();
cameraRotat = GetComponentInParent.<Transform> ();
rb.MovePosition (this.transform.position + transform.forward * Time.deltaTime * 3);
transform.rotation.y = Adapt.transform.rotation.y;
}
///////////////////
And the C# attached to the MainCamera
public GameObject caps;
public int i;
public Vector3 offset;
void Start () {
offset = transform.position - caps.transform.position;
}
void FixedUpdate () {
transform.position = caps.transform.position + offset;
}