I'm using an Oculus Rift with Unity, and am attempting to allow the user to zero-out the orientation of their device when they push a key. The idea is that the camera is frozen looking in a particular direction, and when the user begins the game, whatever direction they're looking in is bound to that camera orientation. I found this forum post, but it only says to use SetOrientationOffset, but doesn't provide code.
I've tried both of the following, independent and together:
OVRDevice.ResetOrientation ();
cameraController.SetOrientationOffset (Quaternion.identity);
However, neither seems to have an effect. I've even tried passing other quaternions into SetOrientationOffset, but that seemed to have no effect.
Does anyone have a working code example?
If different quaternions make no difference then you probably have a game object set in the FollowOrientation variable. If you clear that then passing in different quaternions should have an effect. Alternatively you can rotate the thing you've set in FollowOrientation. Then you need to find the correct orientation to start in. Probably the rotation of the frozen camera is what you need.
Related
There seems to be an issue when i am using VR. The movement I make is not scaled correctly with the movement in the VR. I have to move much further in reality to go where I need to in VR. I am working on the reach with the OVRgrabbable script after finding something online that may help. I am having an issue with getting the X,Y axis to be recognized as objects. Everything else about the code seems to be ok as nothing else is underlined in red.
This image is the notif. i am getting. I am just referencing the x and y axis i think it should operate just fine
I have one suggestion, on the OVRCustomHand.prefab check the configurations on the script OVRCustomSkeleton.cs:
Make sure to check the checkboxes for Update Root Pose (only if your OVRHandPrefab is not parented to OVRCameraRig), Update Root Scale (makes the hand model size is scaled either up or down based on the user’s actual hand size), Apply Bone Translation.
This will make sure the Hand's position is referenced to your scene's global space instead of real tracking space.
Hope it works!
I started to make a simple VR gaze system from scratch, using Unity ARFoundation. First thing was to draw a line from my point of view to "infinity", like a pointer. I have this script running on my AR Session Origin at Update:
myLine.SetPosition(0, transform.position);
myLine.SetPosition(1, transform.position+(transform.forward*1000));
This works on editor, I have a line, and I can turn and move my session origin (my "head" with camera), it follows up.
But, when I use it on mobile... the line keeps still, doesnt turn and move with the device.
What´s wrong?
Oh well... nevermind. I solve it. I needed a reference to the arCameraManager, it holds the head-tracking information.
myLine.SetPosition(0, arCameraManager.transform.position);
myLine.SetPosition(1, arCameraManager.transform.position+arCameraManager.transform.forward*100));
o/
I am trying to give subtle variation of animation to Unity avatar. Currently, avatar moves exactly to what animation keyframe instructs. Animation I am using is Raw Mocap Data for Mecanim by Unity(https://assetstore.unity.com/packages/3d/animations/raw-mocap-data-for-mecanim-5330).
I also noticed that Unity interpolates between keys in keyframe to offer "Smooth" movement.
However, I would like to programmatically change this smoothing(interpolating) in given time interval.
I tried changing the "Curve" in animation inspector tab but it didn't work.
Also, I tried manually changing the interpolation curve in Animation window curves (curve option between Dopesheet and Curves button). However, it looks like I cannot change them because its Read-only file.
How may I change it?
Eventually, I want to make avatar move with certain variation, just like humans do.
Thank you for sharing your time!
I have made a smoke particle effect that I instantiate everytime the player shoots, its working but can not be seen with the background. If I delete the background it's visible, I've tried changing the ordering layer, creating a new layer and putting it above the default, but no matter what it's still below the background. Any ideas?
Assuming you are developping a 2D game, you can use the z axis to set the distance of the elements to the camera (what will be the equivalent to the order of render)
Usually in a 2D game you will have the main camera at -10 in the z axis. So moving in the inspector the backgroun to, lets say z=5 or z=10, and keeping in you particle system in z=0 should solve your problem.
Try this easy trick and let me know if you are still facing problems.
You can check the second half of this video for a better understanding
Also, if you are making a 3D game you can go to the material of the particles and make sure that render face is set to both. I just had that problem and it was annoying me. but that fixed it.
I have an object which has a diffuse shader and on runtime I want the shader to switch to Diffuse Always Visible but this should trigger only if the unit is behind a specific object within the layer named obstacles.
First I tried to switch the object shader with the following code and the shader is changed in the inspector but not in the game during play. I tried placing and calling the shader from the resources and also created seprate materials but its not working.
Here is the code I am using in C#
Unit.renderer.material.shader = Shader.Find("Diffuse - Always visible");
As for the rest I was thinking of using a raycast but not sure how to handle this.
Thanks in advance
I only need the other concept now where the shader changes if a unit is behind an object!
For the trigger, how to handle it will depend a lot on how your camera moves.
To check in a 3D game, raycasts should work. Because whether or not something is "behind" something else depends on the camera's perspective, I would personally try something like this to start:
Use Camera.WorldToScreenPoint to figure out where your object is on the screen.
Use Camera.ScreenPointToRay to convert this into a ray you'll send through the physics engine.
Use Physics.Raycast and check what gets hit. If it doesn't hit the object in question, something is in front of it.
Depending on your goals, you might want to check different points. If you're just checking if something is more than halfway covered by an object, doing a single raycast at its center is probably sufficient. If you want to see if it's at all occluded, you could try something like finding four approximate corners of the object and raycasting against them.
If it's a 2D game or the camera is always at a fixed angle (for example, in a side scroller), the problem is potentially a lot simpler. Add colliders to the objects, and use OnTriggerEnter or OnTriggerEnter2D (along with the corresponding Exit functions). That only works if the tiniest bit of overlap should trigger the effect, and it only works if depth doesn't really matter (e.g. in a 2D game) so your colliders will actually intersect.