Oculus go Inverts axis unexpectedly in unity - c#

I'm developing for oculus go, and I'm making a sky dive like game where the player controls the hovering of the character with the head. I created an empty game object and placed the ovr camera rig inside to move it, then i use camera.main.transform.rotation to get the oculus rotation, and to move the character to the direction the player is looking at. For example, i print the camera.main.transform.rotation and get 4 values from -1 going to 0 and finally 1, what i did to get the tracking was
if(camera.main.transform.rotation.x>0)
{
//move the player up
}
Imagine if the oculus go prints values from 0 to 1 when I look up with camera.main.transform.rotation.x
When I get the apk it's fine and all but sometimes the axis are inverted and I have to restart the oculus go to fix this. Does anyone know why this happends, and what I'm doing wrong?

I had a similar problem with the z-axis controls. I'm doing a racing game for the Oculus go and wanted to control the direction of the car with the LocalControllerRotation.
In fact, the inversion happens when you rotate the oculus more than 180 ° in global space
(0° = LocalControllerRotation.w = 1f, 180° = LocalControllerRotation.w = -1f)
The problem was that the global value of Oculus did not change even after the view was reset. The Oculus scripts reoriented all controllers and cameras, but the values did not. And because my script worked by accessing the values, the result was reversed.
My solution was to check the LocalControllerRotation.w value (should also work for the camera orientation) and then change the input

Related

How to simulate running on Wall like The Flash in unity

Please is it possible to make a Player with rigidbody or character controller run on wall just like The Flash. Please guide me on how to implement this.Here's a link of what I'm talking about. Thank you in advance.
Rotate the player to be vertical to the building, adjust the gravity parameter on your rigid body (make it lower so the added force won't be canceled by it) and just add the force (or set the velocity, whatever makes you happy)
I'm going to assume you already know how to move the player around on the ground. All you need to do is create some form of detection for when they want to begin running on the wall (maybe the player presses a button, or walks up to the wall), at which point you will want to do 2 things: rotate the player to have their feet on the wall, and change gravity to be pulling the player into the wall.
If we assume the player is facing the wall when they go up on it, you can just rotate 90 degrees backwards. Changing gravity should be easy too. Once the player is fully rotated, do something like this
Vector3 newGravityVector = tranform.down.normalized
Physics.gravity = transform.down.normalized * 9.8 //9.8 is the default gravitaty value, feel free to use a different multiplier if you wish.
(this script should be attached to your player)

Pinch and rotate around a point using MRTK and Hololens 1

I'm trying to rotate a beam/cuboid around a pivot using MRTK, Unity, and the Hololens 1 when you're doing the pinch and hold gesture. The beam should remain in place once you've let go of the pinch.
My initial thoughts were to get the cartesian coordinates of the pinch and based on their position relative to the pivot, have the beam rotate by however many degrees needed. E.g. the hand position while pinching is (1,1,0), and the pivot position is (0,0,0). Thus, the beam should be rotated at 45 deg in the XY plane (we ignore the z components). I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2. (https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/Input/HandTracking.html#hand-tracking-events & https://microsoft.github.io/MixedRealityToolkit-Unity/api/Microsoft.MixedReality.Toolkit.Input.IMixedRealityHand.html#Microsoft_MixedReality_Toolkit_Input_IMixedRealityHand_TryGetJoint_).
Does anyone know how to go about doing this or at least point me in the right direction (tutorials/code/assets would be much appreciated!)
Thank you!
I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2
Yes, HoloLens1 does not support hand tracking, such as touching holograms directly with your hands or pointing and committing with hands. It is recommended that you try to use the interaction model Gaze and commit, so that you can easily get the position of GGVPointer.
Pinch to rotate interaction can be achieved by adding the ManipulationHandler component from MRTK to your cube. The component can be configured to allow two hand manipulation like this.
I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2.
There are a few ways to query pointer position. The code below should return the Right GGVPointer position for the hololens.
Vector3 pos;
GGVPointer pointer = PointerUtils.GetPointer<GGVPointer>(Handedness.Right);
if(pointer != null)
{
pos = pointer.Position;
}
In case you just want to rotate the Object around its center,you can use the Boundingbox Component. It creates handles that can be pinched and moved to rotate an object. you can disable the axis you don't want. It works even on the HoloLens 1.

3rd person controller, allow camera through wall and prevent player

im working for 3rd person fighting game between two characters.
I've setup camera to focus enemy and player in same time like Naruto Ultimate Ninja Storm 4, but when camera collide with wall the view angle will be change and both characters will not appear on screen.
in Naruto Ultimate Ninja Storm 4 there is transparent wall around arena which leave empty space between visible object (wall,rock..) and player but allows camera to pass it.
my problem I don't find method to let the camera pass this transparent wall and stop player to pass it.
I tried to get tag of object in collision and disable collider of object when is camera or vice versa but that allow character also to go tought transparent wall
You should create 3 layers, if you haven't already:
Player
Camera
Wall
Put each GameObject in the corresponding layer, then go to Edit->Project Settings->Physics, scroll to the "Layer Collision Matrix" and uncheck the collisions you don't want to have. In your case, you want the collision between the wall and the player, but you have to uncheck the collision between the camera and the wall.
Also, to make this work correctly, make it so that none of the characters, walls, and camera are separate gameobjects.
This is also very useful to remove any unnecessary collision and boost your game performance.

Make object appear right in front of camera OCULUS

I am making a Unity game for Oculus VR using C#.
I want to test a simple jumpscare where the object appears suddenly right into your "face".
I have problems with setting the position of this object. Right now I pass players position and rotation to this function.
public void ScareMe(Vector3 pos, Quaternion rot){
girlSmiling.transform.position = new Vector3(pos.x, 0.9f, pos.z- 1.3f);
//girlSmiling.transform.LookAt (pos);
girlSmiling.transform.rotation = rot;
//other irrelevant stuff
}
I need to maintain y position for my scare (girl) because in Oculus your height is adjustable and it doesn't correspond to your environment, so I need to leave it at 0.9f.
I tried LookAt function but it doesn't work as good as I would like it to work.
The problem remains that girl appears right in front of me only when I look straight. When I move my head around, which is more likely to be a real in game situation for Oculus, she appears a bit to the right or left or even at the back.
I dont understand why it is happening. How can I set her position so she is always facing me right in front of me?
You always can try to make your scare girl being children of your camera-head object. Doing this the object will follow the camera head and rotate with it.
girlSmiling.transform.parent = ...Here you can put the transform of the Camera head.
You can position the object before parenting or after parenting them (with local position should be easier).
I hope this helps, good luck!

Character slowly move up the ground using a humanoid animation type in Unity

I have a marine model used in my start project, which will uncontrollably lift off the ground when running. I import the fbx resources, set the animation type as humanoid and configured the avatar by automatically mapping, set up a animator controller that contains only a running animation. Here is about several seconds after playing:
But when using a generic animation type everything works fine. Any suggestions to fix this while still using the avatar system?
UPDATE:
Configure of my 3D model:
This is obviously caused by root motion. What happens is, one loop of your animation takes the character slightly higher. Adding these slight changes up, you get what you're getting. If you don't need root motion (doesn't look like you do), disable it (from the animator component's settings). If you do, either edit the animation to make sure it fits, or disable root motion along the Y-axis (you can do this from the animation's import settings).
In case you don't know what root motion is, it's when the root bone of your model has animations applied. You obviously can't create the entire animation of character running up and down your levels, and until recently (though not MUCH recently) characters where animated in-place, and moved procedurally via code (I know for a fact that Unreal Tournament 3 uses this method, as would any UDK user). Then, people started wondering how they could make their characters move more realistically? I mean, it's not like you walk forward at a constant rate of 4 km/h, you tend to slow down and speed up during different parts of the walk cycle. The same can be applied to video game characters using the technique known as root motion.
With root motion, you actually move the character forward during its animations. This will cause an animation to look really bad in max or maya, since the character will just snap back to its original place after a loop. However, this data is used intelligently in game engines: Rather than use the absolute position the animation yields, you take the velocity out of it between each two frames, and move your character based on that velocity (Unreal engine actually has a really neat acceleration mode for applying root motion, though I'm not really sure how that would be different from velocity mode). This will make your character move forward at the same rate the animation does, and thus you can actually animate the character's movement as well as its limbs and joints. Moreover, since you're using the velocity and not position data from the animation, it will look exactly as you'd expect it to. If you're interested in this technique, take a look at the Mechanim demo pack they have on the asset store. It makes extensive use of root motion to move the character around.
My company was having a similar issue but we still wanted to keep the "Apply Root Motion" toggle checked. When the same animation played on loop, the model stayed in place but if several different animations were played one after another, this caused the model to rotate / shift in position.
The solution for us was ticking these check boxes in the animation settings for each animation. Root Transform Rotation, Root Transform Position (Y), Root Transform Position (XZ).
I had the same issue a few days ago. I found out that the problem was the Apply Root Motion in the Animator script. Make sure it's unchecked.
Tag your player with "Player" in scene
and use this script
float y;
GameObject player;
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
y = player.transform.position.y;
}
// Update is called once per frame
void Update ()
{
float diff = player.transform.position.y;
player.transform.Translate ( 0, 0,z - diff);
y = player.transform.position.y;
}
it is little hacky soultion but works!!
note: if you want to use y movement at some point just calculate and add it to diff variable.
For those who couldn't solve this issue with 'bake into pose'.
I tried 'Bake into Pose-Y', but it didn't work.
Meanwhile, in FBX > Animation > Motion, I set 'Root Motion Node' as 'Root Transform'(It was 'None' before), it solved my problem. Unity version is 2020.3.34f1.

Categories

Resources