Can I place an object in air - 360 angle (random position) without click instead of find plane in unity Vuforia mid air - unity3d

I'm trying to show my 3D object in mid air. Currently my object shows on click event, but I don't want click event. I just want the object shown in a random position in midair.

if I break your question into two, then,
Vuforia uses "Anchor input Listener Behavior" to receive the input for the mid-air anchor. I am not sure it will work without a click event.
you have to click to lock the mid-air target, you can gamify it by showing a pop up "click to start".
However, there is always a way out. If you go through PlaneManager.cs class then you fill find a method "PlaceObjectInMidAir", you can carefully build logic and call the following lines in Update method but for one time.
if (TrackingStatusIsTrackedAndNormal)
{
this.contentPositioningBehaviour.AnchorStage = this.midAirAnchor;
this.contentPositioningBehaviour.PositionContentAtMidAirAnchor(midAirTransform);
UtilityHelper.EnableRendererColliderCanvas(this.midAirAugmentation, true);
this.midAirAugmentation.transform.localPosition = Vector3.zero;
UtilityHelper.RotateTowardCamera(this.midAirAugmentation);
}
To spawn the gameobjects randomly in 360 degree, you can use instantiate method in random position with "Random.insideUnitSphere" [see the link]
https://docs.unity3d.com/ScriptReference/Random-insideUnitSphere.html
then make that object child of mid-air Achor "Anchor_MidAir".
Hope my answer would give you a start push.
Good luck!

currently my object show on click event i don't wont click event just object show on random position of midair
If I understand that correctly, your object is shown when the mouse is clicked, and instead of this you want to show it in a random position. Here's what you should do:
Don't listen to that click event. If you don't want something to happen on click, just don't write any code that does that!
To teleport an object to a random position, decide what the minimum and maximum values for your object's position are, and do the following:
yourGameObject.transform.position = new Vector3(
Random.Range(minX, maxX),
Random.Range(minY, maxY),
Random.Range(minZ, maxZ));

Related

Unity AR Rotate Scene to match reference point

How to Match a reference point in 2 different AR scenes by position and rotation?
Here are some details about my project:
I have 2 scenes: "new scan" and "load scan". In the "new scan" scene I instantiate a 3d cube and make all the other points relative to it. This is my reference point. Then I instantiate some more points and finally save all the data to the device (my phone).
Next, in "load scan" I load the scene again and instantiate the cube in the exact same world position. For now, I managed to set the right position for each point but the axis is rotated because I start the scene from a different real-world location and different phone rotation.
Based on the cubes which are instantiated in the same place, I need to match the rotation and the position of the scene so the points will appear in the same relative position as the first cube.
Note: one can assume that the cube will instantiate with the user standing in the same direction as the desired position. But Do NOT assume that the user starts the "load scan" scene in the same direction as the "new scan" scene (which effect the whole scene rotation).
Here is a visualization of the problem:
Image of New Scan:
Image of Load Scan:
Thanks
If you want to make sure that the cube will appear in the same position/rotation in every AR session you have several options:
Use an Image marker
Use ARWorldMap (iOS exclusive)
Use a Cloud Tracking solution (google cloud anchors / Azure spatial anchors)
Of course you can also try to make the user place the cube correctly themselves, or redesign your app to work without these restrictions.
So I've found a solution but this is not the ultimate solution:
First, make a class with public static parameter so we can pass it through other scripts and scenes. Something like that:
public static class SceneStage
{
public static int ResetScene = 0;
}
Now, every time the camera turns on, check the SceneStage.ResetScene state. If value == 0 don't do anything, otherwise ask the user to stand facing the desire direction and then press a button, which call the function ResetScene:
private void ResetScene(int _scene)
{
var xrManagerSettings = UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager;
xrManagerSettings.DeinitializeLoader();
SceneManager.LoadScene(_scene); // reload current scene
xrManagerSettings.InitializeLoaderSync();
}
Here I send the scene build index to the function with:
ResetScene(SceneManager.GetActiveScene().buildIndex);
So basically, the flow is like that: for the first time we open the scene (when SceneStage.ResetScene = 1) -> change the value to 0, and reset the scene. The second time don't do anything, but when we leave the scene set the value back to 1 so the next scene will reset too (because the ARPose driver still tracking the environment).

How to you get AVAudioEnvironmentNode.listenerPosition to update?

I am trying to use an AVAudioEnvironmentNode() with AVAudioEngine and ARKit.
I am not using ARSCNView or any of the other ARViews, this is just a plain ARSession.
I have a sound source -> AVAudioEnvironmentNode -> AVAudioEngine.mainOut.
I understand how set the position of the sound source. I am trying to figure out how to move the audioListener. Because I want to walk around the sound source in space.
The Apple Documentation says that to update the node's listener position you use.
AVAudioEnvironmentNode.listenerPosition = AVAudio3DPoint(newX, newY, newZ)
When I pass the ARCamera's forward and up to the node, that seems to change fine. However when I trying to change the position, I do not hear anything, and when I print a debug of listenerPosition, the output stays at zero origin, even those the camera's position is moving.
Is there something I have to do to make the AVAudioEnvironmentNode movable to take a new position?
Thanks.

Gradually decreasing the velocity of an object through animation in Unity

I need to create 2 animations,
one is of an object going from point A to point B at a constant velocity.
the other is of an object starting from point A but with a gradually decreasing velocity as it reaches point B until it comes to a stop.
I tried decreasing the animation speed every second to achieve this result with no luck.
Any ideas?
As you may have noticed when you work with animation in Unity there is no such thing as changing the velocity of an object. What you need to do is give your object an Animator and create a new Animation.
Then on the animation timeline press the red dot (record button) and then place your object on point A.
Next, on the time line you want to select the exact second that you want your object to come to a stop and after that move the object on point B.
Now, the more seconds there are in between the 2 keys, the more time it's going to take for the object to travel.
To make it gradually slower instead of it just travelling slowly:
On the animation panel you will see 2 tabs. Dopesheet and Curves. Hit Curves and play around with them till you have a satisfing result.
Documentation on using Curves

Unity - Animation Loops?

I am using an FBX 3D object file as a game object in my project which have further sub assemblies. Now i want to animate a part of the assembly.
I followed this process:
Select the part which I want to animate.
In the animation panel create one animation.
Add property > transform > position
Using pivot, i move that part to the location where I want to animate.
Challenges
Animate in loop. Moreover if I Select animation file, it does not show Wrap mode
( 1. I don't want any loops in my animation, even after deselecting loop-time it does loop. - I dont know why?
It is animating in reverse. suppose if the object needs to go from position x:3 to position x:8 but it goes from position x:8 to position x:3
the above point happens in loop. just like a ping pong)
Animates in reverse.
I take the whole animation as one loop i.e Part comes out of assembly and goes back and repeating for infinite time.
I want to stop the animation till the point it comes out.
Any help will be appreciated

Drag object with touchesMoved along offset vector / delta?

In the touchesMoved method, what is the math to have an object on the screen move along a dragging touch vector? For instance, if I touch beneath my object (Y > object.y), and drag "up", I want the object to move from its current x,y location along the same vector that my finger moves.
Currently I have it working that the drag motion snaps my object to my finger's location, but sometimes my finger hits the edge of the screen before I get my object positioned correctly.
If I know my "touch down location" and the "current touch location" what is the math to determine where to move object.position?
I hope that you have already received the answer of figured it out yourself, but.
Assume that your object's Upper Left Corner (ULC) is at Object.X, ObjectY.
Assume that the CGPoint returned by touchsBegan is Touch.X, Touch.Y.
The offset (Delta) will be:
Delta.X = Touch.X - Object.X
Delta.Y = Touch.Y - Object.X
Subtract these from each point returned by touchesMoved and your ULC should move as you expect rather than snapping to your finger.
Good luck.
I would look into UIPanGestureRecognizer. It's what I use when I want to accomplish something like what you are describing.
This is what I used to learn about them but then took it further in other forms:
http://www.cocoanetics.com/2010/11/draggable-buttons-labels/
Good luck!