I have some Rotation problems
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;
}
Hey, if I understand correctly you want the camera to turn and face your capsule?
If so, the code you posted only deals with position.
For rotation, you could use Transform.LookAt(). http://docs.unity3d.com/ScriptReference/Transform.LookAt.html
O$$anonymous$$, then line 24 of the capsule script will be the focus of your investigation. You have set it to the Y rotation of the CardboardAdapter which will make your capsule face the same direction of the CardboardAdapter for the Y direction.
Does this CardboardAdapter have some 3rd party script, I can't see any reference to it in the Unity documentation?
FYI: Best use Add comment above my two posts for replying.
First, thanks to help me.
Yes there are more things than it on the objects :
$$anonymous$$ain Camera : There is the StereoController script (without him can't see into the two CadboradAdapter's children cameras)
CardboardAdapter (child of $$anonymous$$AinCamera) : there is the CardboardHeadscript(don't really know what he does...) The cardboardSdk.unitypackage is here if you want to see : https://github.com/googlesamples/cardboard-unity
But i display on the screen the axes and you have to know that it works but not for all angles :
Actually, it goes forward (the both rotation.y axes betwen -1 and 1 are displayed) and so -1 = +1 (180 = -180) and what i see is when i pass to the positive at negative or negative to positive it doesn't goes where i want anymore there is a little hysteresis that makes my capsule going in the wrong direction. (I know i'm not clear but it is already not clear for me...)
Now I'm sure about what's happening there is just an hysteresis problem, it is a double hysteresis because it occurs for two senses of rotation so i explain you precisely if you don't know what it is :
I explain you for the sense from positive to negetive :
so i'm at 0.8 and I go to 0.99 --> i continue and it keeps the 0,99 and decrease until about 0.8 where he understand "oh i'm not in postive direction!" so he puts a $$anonymous$$us and it works again.
For the other sense this is the contrary Am I clear enough ?
If it's a double hysteresis problem as you describe then it would be something inherited from your Adapt GameObject, given you use rotation.y unchanged. I have no experience of using Google Cardboard. I'll presume you have check out the Demo scene to gain an understanding of how the unity package works.
Google around, perhaps there is a social platform specific for Unity developers using this package. Otherwise, I hope someone else can help you :)
yes i looked but it's not worth because you can't move xD. you know i've wrote another code in C# which works great but i didn't succeed to just update the rotation.y, I update all the rotation so my capsule doesn't stay standing with the y axis toward the sky if I rotate my head on others axes that the Y^^ . So you'll tell me "It is not a problem" but IT IS, because in my app i don't just stay on the floor i've some stairs and if the player look toward the stairs the capsule lie down in function of the CadbordAdapter axes and so she doesn't climb the stairs. thanks to answered me ! :D
You misunderstand, I didn't say there was not a problem. To summarise my understanding the problem is on this line.
transform.rotation.y = Adapt.transform.rotation.y;
You need to find out how Adapt.transform.rotation.y is used.
Best wishes :)
Answer by arkea · Oct 29, 2015 at 10:57 AM
no that is not what i want. The capsule is under the camera and she follow his local z axis and the camera follow the position of the capsule just for staying above the capsule
Your answer
Follow this Question
Related Questions
Quaternion Roation Mouse Script 0 Answers
Fix rotation skipping 0 Answers
Camera self rotation script problem 1 Answer
Rotate camera like VR on mobile 3 Answers
Switch between touchscreen and Google VR to control the Unity camera 1 Answer