I'm developing an android augmented reality game using unity 3d engine and vuforia extension where I need to move a character over a image target.
The problem is when I associate the character to the image target (as a child of image target) the movement is like the character is "glued" to the plane, it barely moves from his position, it moves very slowly.
I already tested without using augmented reality and the moving of the character is completly fine, so I dont know what am I doing wrong ...
Thanks in advance.
There's no need for the object to compulsorily be a child of the ImageTarget. AR will work both ways.
Wherever you place your Object, it will calculate the relative distance of the ImageTarget and place the Object there automatically. So if your Object is on the Image Target(not a child) It will show the object on top, as it is. Just make sure you don't make the AR Camera a parent/child of any other object.
As for the object following the object, you can simply use the Tracking functions to Enable and Disable tracking, so the object disappears
I really hope this solves your problem.
I think I know what it is! Check your Inspector Panel to see if you've got a Rigidbody Element. They're usually very difficult to handle, try unchecking the Rigidbody element and see if it's solves anything.
Related
In my 2d Unity project, I have a Canvas with an Image that I want for a Background.
I have 2 gameObjects in front of this background. But no matter how much fiddling I do with Pos Z, Sorting Layers, or hierarchy sorting, the image is always in front of the objects.
Gif above shows in 3d mode that even though the image is clearly behind these objects, it will always appear over them if they overlap.
Hierarchy:
Main
Camera (Inspector: https://i.imgur.com/Q5a52cf.png)
BackgroundCanvas (Inspector: https://i.imgur.com/m9Pxr6B.png)
BackgroundImage (Inspector: https://i.imgur.com/jTx7pEW.png)
Object1 (Inspector: https://i.imgur.com/YcClEhk.png)
Object2
Any advice to rescue me from this madness is much appreciated.
Set the sprite renderer's transform z value to 0 instead of 100
If that does not solve, please specify camera properties also, so I can try to recreate the exact setup.
Try clicking on Layers -> edit layers, inside sorting layers you can change the order grabbing layer, everything upper appears behind in the camera.
You could create a layer called Object
Assign it to the game objects.
Create an object camera
culling mask -> object layer
depth bigger than you current main camera.
Set it to Projection -> Orthographic
Clear flags -> solid colors.
canvas Render Mode -> Screen Space - Camera and assign the Render Camera to be the Object Camera
Inspector tab of the object or background.
Sprite Renderer.
Additional Settings.
Sorting Layer.
change it to a different layer.
Had this same issue and was able to fix it with these steps:
In canvas settings change Screen Space Overlay to Screen Space Camera
Set the camera variable to the one you are using for your scene.
I figured out a workaround. I basically created a VisualElement inside the UI Builder and set a render texture to the background. Then I added an extra camera to my project to view all the sprites that needed to be on top. That camera feeds the render texture, so now everything that camera sees is forced to be on top of the UI Document as the background of that VisualElement. If you want control over the whole screen, just set the VisualElement position to absolute and max out its dimensions. If your game doesn't have a fixed aspect ratio it might cause some stretching, but other than that I cant really tell the difference. Sorting layers for the UI Documents are broken and unity needs to work on that. This is the best option I've found. Hope this helps.
I had the same problem and I fixed it by attaching the camera to the canvas which is screen space and finally changing the sorting layer of my object to -1.
I am new to Unity and Oculus. I have a bunch of images (their path and other information are loaded from a JSON file) which I am trying to render in a VR room. And want to give the user an experience that he can move these images within that room using Oculus Touch.
I placed an Empty Object which has a script that iterates through JSON and creates a prefab object (which has Rigid body,Box Collider and OVRGrabbable -so that it can be grabbed in VR, components). Moreover this prefab object has a script which is responsible to load images in a Sprite.
What is working?
Images are getting rendered and can be grabbed and moved.
What is not working as desired?
I followed this tutorial, and as shown here angles of the cube are persisted pretty fine. But when an image is grabbed and rotated, it doesn't persist it's side angles. As shown in following image:
Question
Is there any way that I could fix it? I tried to look for it online but as I am new to Unity I am not quite sure what exactly I am missing.
Any clues would be really appreciated.
I think the problem lies in your hierarchy. Your Images game object (the parent of your DisplayImage) has a scale of (1.88,1,1). Trying to rotate child objects whose parent object have non-uniform scale in Unity gives you funky results. Try resetting the scale of your Images object to (1,1,1) and see if that helps.
This behaviour occurs because of the nature of the "parent/child" relationship. The child's coordinate system is relative to it's parents. We can think of it as the parent defining a coordinate system for our children. This is what we call local space. So, when we perform any linear transformations on the parent, it's like we're performing them on the whole parent coordinate system that our children are using to define their orientation. So translating the parent will move all of its children with it, because our whole local coordinate space has moved with the parent. Note that our children will still have the same localPosition, but their global position will have changed.
The same logic applies to scaling and rotation. Rotating the parent essentially rotates the whole coordinate space that our child is using around the center point of the parent (which would be the point (0,0,0) in local space). So all children would then be rotated as if they were an extension of the parent object.
In our situation we've scaled our parent, thus scaling the whole coordinate system we use to define our child object. This means that anything using the parent's coordinate space will also be scaled according to the parent's scale. In our situation, the parent was scaled by (1.88,1,1). So everything attached to the parent was also scaled along the parent's X-Axis by 1.88, resulting in the weird effect seen in your screenshots. Despite rotating our child object, it's still scaled along the parent's X-axis.
(Link to the official documentation on this.)
The solution to this is to apply your linear transformations as deep in the hierarchy as possible. Here, instead of scaling the parent, scale the child. If the parent object needs to be scaled, or its scale changes on the fly, another solution would be to remove the child from the parent/child hierarchy and manipulate its transform based on the old parent's transform in a script. In this case you could set the unlinked child's position and rotation to the parent's position and rotation, but ignore the scale.
Following #Adam Stox's answer, I share you a solution that usually work in this case (link tho the original answer):
Don't child the objects directly to a non-uniformly scaled parent -
child this non-uniform object to an empty object, which will be the
parent of the other objects too; since an empty object is scaled
1,1,1, childing other objects to it don't cause this problem.
I don't know your object hierarchy, but in the link you can find an example, so you can adapt to your specfic case.
You could use the RigidbodyConstraints to lock the rotation in once axis.
The other option would be to fix the rotation in LateUpdate using a script.
If the problem only occurs on sprites, then try making it a child of a cube, where you disable the renderer.
There could be more than one things at play, and it's hard to tell without seing the prefab hierarchy or the source of OVRGrabbable.
One thing that comes to mind is that you should manipulate the position and rotation of the object through its rigidbody
The prefab could have a bunch of builtin transformation that persists, is everything properly align before you interact with the collider? Also somehow the rotation of the image to the collider is similar to the rotation of the collider relative to the world. Could it be that you nested two objects?
It's a 360 Video application on Unity 3D.
I want to place several objects around the camera (which has a fixed position), but I need this objects to have the same distance (same radius) from the Camera (which is the center). How can I do this? Either on Editor or by code.
I have been manually displacing objects around the camera, by dragging them by arrow tool. But it's as inaccurate as a pain to do. :)
Any light on this would help me a lot! Not only me, but anyone working with 360 videos in Unity.
Thank you all in advance!
To solve your problem, an easy solution would be to add a child "child_of_camera" to your camera and then add a child "child_of_child" to the "child_of_camera".
Now that you've done this, move the "child_of_child" away to however far from the camera you'd like it to be. After this, apply the random rotation you'd like to "child_of_camera".
Duplicate "child_of_camera" to however many objects you'd like on screen and then rotate them all to your preference.
Now, when you're moving around the camera, these children will follow along with the camera.
If you're looking so that the rotation of the camera doesn't affect the objects there are two ways you can handle this:
Place camera and "child_of_camera" (this name would now be misleading and should be renamed) under an empty GameObject and move "empty_GO" on the X,Y,Z axis instead of the camera.
or
Create a quick script to attach onto "child_of_camera" so that it always sets the "child_of_camera"s world space rotation to Vector3.zero.
As I stated in the comments, this solution is most likely not the optimal way to fix your problem but it is definitely a very simple solution that is easy to understand and implement. I hope it helps.
I am new to Unity and Oculus. I have a bunch of images (their path and other information are loaded from a JSON file) which I am trying to render in a VR room. And want to give the user an experience that he can move these images within that room using Oculus Touch.
I placed an Empty Object which has a script that iterates through JSON and creates a prefab object (which has Rigid body,Box Collider and OVRGrabbable -so that it can be grabbed in VR, components). Moreover this prefab object has a script which is responsible to load images in a Sprite.
What is working?
Images are getting rendered and can be grabbed and moved.
What is not working as desired?
I followed this tutorial, and as shown here angles of the cube are persisted pretty fine. But when an image is grabbed and rotated, it doesn't persist it's side angles. As shown in following image:
Question
Is there any way that I could fix it? I tried to look for it online but as I am new to Unity I am not quite sure what exactly I am missing.
Any clues would be really appreciated.
I think the problem lies in your hierarchy. Your Images game object (the parent of your DisplayImage) has a scale of (1.88,1,1). Trying to rotate child objects whose parent object have non-uniform scale in Unity gives you funky results. Try resetting the scale of your Images object to (1,1,1) and see if that helps.
This behaviour occurs because of the nature of the "parent/child" relationship. The child's coordinate system is relative to it's parents. We can think of it as the parent defining a coordinate system for our children. This is what we call local space. So, when we perform any linear transformations on the parent, it's like we're performing them on the whole parent coordinate system that our children are using to define their orientation. So translating the parent will move all of its children with it, because our whole local coordinate space has moved with the parent. Note that our children will still have the same localPosition, but their global position will have changed.
The same logic applies to scaling and rotation. Rotating the parent essentially rotates the whole coordinate space that our child is using around the center point of the parent (which would be the point (0,0,0) in local space). So all children would then be rotated as if they were an extension of the parent object.
In our situation we've scaled our parent, thus scaling the whole coordinate system we use to define our child object. This means that anything using the parent's coordinate space will also be scaled according to the parent's scale. In our situation, the parent was scaled by (1.88,1,1). So everything attached to the parent was also scaled along the parent's X-Axis by 1.88, resulting in the weird effect seen in your screenshots. Despite rotating our child object, it's still scaled along the parent's X-axis.
(Link to the official documentation on this.)
The solution to this is to apply your linear transformations as deep in the hierarchy as possible. Here, instead of scaling the parent, scale the child. If the parent object needs to be scaled, or its scale changes on the fly, another solution would be to remove the child from the parent/child hierarchy and manipulate its transform based on the old parent's transform in a script. In this case you could set the unlinked child's position and rotation to the parent's position and rotation, but ignore the scale.
Following #Adam Stox's answer, I share you a solution that usually work in this case (link tho the original answer):
Don't child the objects directly to a non-uniformly scaled parent -
child this non-uniform object to an empty object, which will be the
parent of the other objects too; since an empty object is scaled
1,1,1, childing other objects to it don't cause this problem.
I don't know your object hierarchy, but in the link you can find an example, so you can adapt to your specfic case.
You could use the RigidbodyConstraints to lock the rotation in once axis.
The other option would be to fix the rotation in LateUpdate using a script.
If the problem only occurs on sprites, then try making it a child of a cube, where you disable the renderer.
There could be more than one things at play, and it's hard to tell without seing the prefab hierarchy or the source of OVRGrabbable.
One thing that comes to mind is that you should manipulate the position and rotation of the object through its rigidbody
The prefab could have a bunch of builtin transformation that persists, is everything properly align before you interact with the collider? Also somehow the rotation of the image to the collider is similar to the rotation of the collider relative to the world. Could it be that you nested two objects?
I am thinking of building a game like the sims and was thinking of how I could make the characters interact with any object without having to systematically change the character's code and prefab whenever I decide to add new furniture and props to the library. I have had an idea that consists of having my animations attached to the furniture itself rather than having it attached to the character (which would require a lot of memory and extra code if we had a lot of furniture in the game library!). I was thinking about it and had in mind that I could add a rig skeleton in Blender that has the desired animation(s) but not rig any specific object - so that I only have the animation, the location, rotation and scale of the bones! and since the characters' rigs are the same as the skeleton's rig in the furniture's animation, they could be compatible!
I hope this makes sense...
The thing is that I realise at this stage that I do not know the Animation class very well, and I am not sure if / how I can use the animation attached to the furniture to make my character interact with it...
Can Animation.Play() take multiple arguments apart from the animation to play and the play mode? Is it possible to specify which object has to play the animation? I am talking about doing all of this from the script - I write in C# by the way... and I might attach the script to the camera so I hope the script does not have to be necessarily attached to the character prefab in order to play the animation... Though I don't mind creating a function in the character's script if necessary!
I am not new to Unity but I have mostly been using cars and character controllers, so I haven't dealt with much animation coding yet...
I thank you in advance for your help and apologise for my weird english - I live in France! ^^
Mecanim performs retargeting of humanoid animations, so for what concern that specific case, you should be able to use the same rig and set of animation clip on different models.
For what concern grabbing furniture, you don't need the object to be rigged. You can use IK to precise move your character's hand toward the target object and then parent it to the relative joint in the hierarchy.