- Home /
How to stop the player rotation after i stop the camera?
so i placed a google vr camera to my player and my camera has a script with
public GameObject target;
Vector3 rotateDirection;
float y1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
y1=transform.rotation.eulerAngles.y;
rotateDirection = new Vector3(0, y1, 0);
Quaternion rotatedri = Quaternion.Euler(0f, y1, 0f);
target.transform.rotation = Quaternion.Slerp(target.transform.rotation, rotatedri, Time.deltaTime);
}
i know the player will continue spinning while the camera y angle still has a value so my question is how to stop the player after i stop moving my camera ? or make the code better, im a beginner sorry #SorryForMyBadEnglandImNotEducation
Wow, seems like your head is a mess.
Slerp will go from one point to other, over time. Your first point is the current, rotation, that's right. The second point should be your target rotation, which should depend on how much the player has rotated his head (Not sure how to do that, maybe an Input.GetAxis("Horizontal") ?)
So, you need to modify your "y1" only when the player rotates his head
Not sure if this will work, but try deleting y1=transform.rotation.eulerAngles.y, and replacing it with y1 = Input.GetAxis("Horizontal");
"seems like your head is a mess" well thats right, im kinda living trash i tried your suggestion and its not working :/
Try this one
y1=InputTracking.GetLocalRotation (VRNode.CenterEye).eulerAngles.y;
I never worked with RV to be honest.
Also, that will rotate the camera only upwards and downwards
i tried putting main camera as the parent of the player this will rotate the player too and this will fix the problem but when i rotate to look upward ( to look at the sky ) the player will rotate too he will go on horizontal position, please help
So you want to rotate the camera or the player? I think you weren't very clear with your problem. What was exactly happening with the code you used before, and what did you expect to happen?
Answer by BGOKMEN14 · May 15, 2018 at 12:22 PM
Hello @SirYo!
I am not quite sure what you meant by stop the player rotation after camera stops, however, I believe I this is what you are looking for:
public GameObject target;
Vector3 rotateDirection;
float y1;
float y1OldValue;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
y1=transform.rotation.eulerAngles.y;
rotateDirection = new Vector3(0, y1, 0);
Quaternion rotatedri = Quaternion.Euler(0f, y1, 0f);
target.transform.rotation = Quaternion.Slerp(target.transform.rotation, rotatedri, Time.deltaTime);
if (y1 != y1OldValue) { //here the camera is still moving
y1OldValue = y1;
} else //here is when the camera stops
{
//stop the player here
}
}
I hope this helps!