Forum Discussion
kenter
12 years agoHonored Guest
Camera Y rotation adds rotation force to player?
Hi all, I'm trying to implement something that seems fairly straightforward, but I can't seem to make it work...here it goes...
Currently, "Tracker Rotates Y" makes it so that the camera Y rotation sets the player's rotation when using the OVRPlayerController prefab. In order to rotate 360 degrees, you would need to rotate 360 degrees in physical space. I want to modify this so that the camera Y rotation adds a continuous rotation force to the player. The further you look to the left or right, the more force is added to the rotation. Think of it like a rotation throttle. The more you look to the left, the faster you will rotate. The effect of this would be that you could rotate your player in circles without having to literally rotate your head 360 degrees, you could simply look left and you will continuously rotate to the left until you look to the right, at which point you will start to rotate to the right.
Currently, "Tracker Rotates Y" makes it so that the camera Y rotation sets the player's rotation when using the OVRPlayerController prefab. In order to rotate 360 degrees, you would need to rotate 360 degrees in physical space. I want to modify this so that the camera Y rotation adds a continuous rotation force to the player. The further you look to the left or right, the more force is added to the rotation. Think of it like a rotation throttle. The more you look to the left, the faster you will rotate. The effect of this would be that you could rotate your player in circles without having to literally rotate your head 360 degrees, you could simply look left and you will continuously rotate to the left until you look to the right, at which point you will start to rotate to the right.
3 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionI believe this can be done, but not with the OVRPlayerController (at least not without serious modification). You may have to create your own player controller and read the tracking data from the OVRCameraController. I think the function is called 'GetTrackerOrientation()' or something like that.
- kenterHonored GuestI'm away from my work comp but I was thinking of something like this as a possible solution...
Vector3 a = gameObject.camera.transform.rotation.eulerAngles;
float rotationStrength = 0.2f;
float rotationAmount = a.y*rotationStrength*Time.deltaTime; // degrees of rotations per second
Transform b = gameObject.transform.parent.transform;
b.Rotate( 0, rotationAmount, 0);
I would attach it to the OVRCamera Component which would have a gameobject as a parent. I don't need the OVRPlayerController so will remove it... crazy? thoughts? - Felix12gHonored GuestIf you store the "forward" view orientation at the beginning with the GetTrackerOrientation() call that cyber mentioned, you can get an easy input right from the headset without needing to mess with the cameras. Checks after the center is stored would give you an angle difference, you'll just want to pull out the Y axis and multiply.
I'm guessing this approach should work, its pretty close to what you've posted, but I think working with the tracker rather than the camera angles is probably going to be easier. The other aspect here is that you can decouple the camera from the heirarchy of the whole system if you wanted and it would still work fine.
Other note, if you're going to be running this every frame, store a reference to the Transform you're going to be rotating, calling the components like that is more expensive.
public class TrackerTurn : Monobehavior {
Transform rootObjToSpin;
forwardRotationVariable = blah; //I think it returns a quaternion?
float turnSensitivityMultiplier = 1f; //Use this to multiply the rotation amount
float turnInputVariable = 0f; //Store your input, then use it however you want
void Awake()
{
forwardRotationVariable = GetTrackerOrientation();
}
void Update()
{
currentRotationVariableLocal = GetTrackerOrientation();
float yDifference = GetGoodAngleValue(forwardRotationVariable, currentRotationVariableLocal);
turnInputVariable = yDifference * turnSensitivityMultiplier; //Clamp it to -1/1 if you want
}
float GetGoodAngleValue(float forward, float current)
{
return compare the two, grab the y and spit that angle as a positive or negative amount back out;
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 months ago
- 3 years ago