Tap to Place Objects using AR Foundation 5 Unity 2023 with XR Origin & AR Session

  Рет қаралды 11,092

Xienna Studio

Xienna Studio

Күн бұрын

Пікірлер: 45
@christopheradiprayoga623
@christopheradiprayoga623 Жыл бұрын
Thank you for sharing this info, looking forward for next video 🔥
@mdrafi9074
@mdrafi9074 2 ай бұрын
thanks for the details
@noorain8259
@noorain8259 11 ай бұрын
Good work! Keep it up. Make more videos. Create video on object detection and pop up message appearance about object name on the object detection.
@nutvers1.0n
@nutvers1.0n 2 ай бұрын
Thank you
@Shorkiedokey
@Shorkiedokey 2 ай бұрын
Thanks!!
@cgmoussalli
@cgmoussalli 5 ай бұрын
Just wanted to thank you for your effort 🫡
@galindoxrafa
@galindoxrafa Жыл бұрын
Great video!!! It Helped me a lot as the XR Origin is new and there's few tutorials. One question, how could you add a second gesture, for instance with 2 fingers rotate the Object. Thank you
@xiennastudio
@xiennastudio Жыл бұрын
Glad it helped! I plan on creating a video about rotating and scaling the model using touch gestures. I will add the script to this comment first. You will need to use EnhancedTouch for this docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/Touch.html#enhancedtouchtouch-class
@xiennastudio
@xiennastudio Жыл бұрын
Hi, here is the script for 2 fingers to rotate the object. If there is any issue please tell me. using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.ARFoundation; using UnityEngine.XR.ARSubsystems; using UnityEngine.InputSystem.EnhancedTouch; using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch; [RequireComponent(typeof(ARRaycastManager))] public class PlaceOnPlaneRotate : MonoBehaviour { [SerializeField] [Tooltip("Instantiates this prefab on a plane at the touch location.")] GameObject placedPrefab; /// /// The instantiated object. /// GameObject spawnedObject; public float minTurnAngle = 0; public float pinchRatio = 1; ARRaycastManager aRRaycastManager; List hits = new List(); void Awake() { aRRaycastManager = GetComponent(); } private void OnEnable() { TouchSimulation.Enable(); EnhancedTouchSupport.Enable(); } private void OnDisable() { TouchSimulation.Disable(); EnhancedTouchSupport.Disable(); } void Update() { int touchCount = Touch.activeTouches.Count; // If one finger touch the screen. if (touchCount == 1) { Touch touchZero = Touch.activeTouches[0]; // Check if the raycast hit any trackables. if (aRRaycastManager.Raycast(touchZero.screenPosition, hits, TrackableType.PlaneWithinPolygon)) { // Raycast hits are sorted by distance, so the first hit means the closest. var hitPose = hits[0].pose; // Check if there is already spawned object. If there is none, instantiated the prefab. if (spawnedObject == null) { spawnedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation); } else { // Change the spawned object position and rotation to the touch position. spawnedObject.transform.position = hitPose.position; spawnedObject.transform.rotation = hitPose.rotation; } } } // Rotate // If two fingers touch the screen at the same time. else if (touchCount == 2) { // If no spawnedObject, don't do anything. if (spawnedObject == null) return; Touch touchZero = Touch.activeTouches[0]; Vector2 touchZeroPos = touchZero.screenPosition; Touch touchOne = Touch.activeTouches[1]; Vector2 touchOnePos = touchOne.screenPosition; // Check the delta angle between them. // Get the angle between the two touch points. float turnAngle = GetAngle(touchZeroPos, touchOnePos); float prevTurn = GetAngle(touchZeroPos - touchZero.delta, touchOnePos - touchOne.delta); // Get the delta of the angle between the two touch points. float turnAngleDelta = Mathf.DeltaAngle(prevTurn, turnAngle); // If it's greater than a minimum threshold, it's a turn. if (Mathf.Abs(turnAngleDelta) > minTurnAngle) { Vector3 rotationDeg = Vector3.zero; rotationDeg.y = -turnAngleDelta; spawnedObject.transform.rotation *= Quaternion.Euler(rotationDeg); } } } private float GetAngle(Vector2 pos1, Vector2 pos2) { Vector2 from = pos2 - pos1; Vector2 to = new Vector2(1, 0); float result = Vector2.Angle(from, to); Vector3 cross = Vector3.Cross(from, to); if (cross.z > 0) { result = 360f - result; } return result; } }
@rubz5706
@rubz5706 Жыл бұрын
Thank you...
@suesuweni286
@suesuweni286 Жыл бұрын
Make more video please ! Thank you !
@xiennastudio
@xiennastudio Жыл бұрын
I will, thank you!
@maheshp2048
@maheshp2048 Күн бұрын
hi im having black screen issue in the unity 2022.3.45f1, no camera view, onl;y the scene view is visible why?
@alpharhomedia9006
@alpharhomedia9006 10 ай бұрын
great tutorial, its very clear. I have follow all your instruction ( i guess ) but after i build to my android its just show black screen, what should I do?
@xiennastudio
@xiennastudio 10 ай бұрын
Hi, please check if your device is in the supported list developers.google.com/ar/devices
@alpharhomedia9006
@alpharhomedia9006 10 ай бұрын
@@xiennastudio thanks for the reply, sorry for missing this detil, yes my android phone is listed, also support depth API, digging for answr in the internet, I found to turn the camera backgorund, but there is no turn off camera background option in my Unity only background color picker
@xiennastudio
@xiennastudio 10 ай бұрын
@@alpharhomedia9006 Try to check if the app has the necessary camera permissions in your phone settings. In Unity, make sure there is no issue in the Project Validation.
@AmirhosseinRabei
@AmirhosseinRabei 3 ай бұрын
I have follow all your instruction but after i build to my android its just show black screen too,and my phones camera not openning. what should I do?(my phone supports ar core)
@drizzy6087
@drizzy6087 3 ай бұрын
ur phone doesnt have ARCore, it is not supported on your phone brother, if you cant find google depth in your play store then the arcore built in feature is not available on your phone
@aryanaggarwal6124
@aryanaggarwal6124 6 ай бұрын
is there a way to remove the orangeish part that spawns on the plane??
@noupo
@noupo Жыл бұрын
Hey Xienna, thank you for the tutorial! Sadly my phone did not support AR Core, are there any alternative for it?
@xiennastudio
@xiennastudio Жыл бұрын
Hi, thank you for watching! I am not really sure about alternative. I think you can use EasyAR, Vuforia, or Wikitude, but you need to pay to use their SDK. I am not able to find any free alternative.
@rubz5706
@rubz5706 Жыл бұрын
It's working fine on my XR simulation but when I build it on my android phone thing opens fine but it's not detecting any plane and tap to place is not working any solutions for this.
@xiennastudio
@xiennastudio Жыл бұрын
Hi, may I know which Android phone you are using? Have you tried it on different phones or different locations? Your environment may not be suitable for plane detection. ARCore plane detection is not really good at detecting reflective surfaces, complex backgrounds, and low light conditions. Make sure that your environment is well-lit and free of reflective surfaces.
@lingeleora6212
@lingeleora6212 3 ай бұрын
how do I replace game object with the 3d model that I've created?
@xiennastudio
@xiennastudio 3 ай бұрын
Sorry for the late reply. It's the same as in the video 01:42, but instead of creating a new cube, use the 3D model that you have.
@nadilahhasfahani7405
@nadilahhasfahani7405 9 ай бұрын
hello xiena, i have some error on my unity. i dont have asset folder xr environment view manager. can u help me? thankyouu🙏🏻
@xiennastudio
@xiennastudio 9 ай бұрын
Hi, have you added XR Simulation to your project? If you haven't, you can check my other video on how to do it kzbin.info/www/bejne/gn7XfIWih8R4g7M
@宣成金
@宣成金 Жыл бұрын
where is the video about xr simulation?
@xiennastudio
@xiennastudio Жыл бұрын
Hi, the XR Simulation video is not out yet, but it will be released within the next few days.
@xiennastudio
@xiennastudio Жыл бұрын
Hi, the XR Simulation video is out now 😄kzbin.info/www/bejne/gn7XfIWih8R4g7M
@nainamkumar
@nainamkumar 11 ай бұрын
Is there a way to tap and place a 2D image?
@xiennastudio
@xiennastudio 11 ай бұрын
2D image should be the same, just need to use Canvas world space in the AR Prefab instead of a cube. Is there any issue you are facing?
@nainamkumar
@nainamkumar 11 ай бұрын
I keep getting an error saying: Cannot add script. The script is and editor script when I try to add the TouchControls script to my Game Object. The script is not in the editor folder and I followed all the steps in the end for using the new input with the editor to create the script. Please help me :)))
@xiennastudio
@xiennastudio 11 ай бұрын
Hi, the TouchControls script shouldn't be added to any game object. You should add any PlaceOnPlane script to the XR Origin game object. You can download all the scripts in my video here: www.patreon.com/posts/87675816
@峰碩張-k2s
@峰碩張-k2s 10 ай бұрын
I do this and my phone can find plane but no camera,all I can see is sky not real world, please help me
@xiennastudio
@xiennastudio 10 ай бұрын
Hi, can you contact me via email at xiennastudio@gmail.com or on Discord at @xiennastudio
@gialong1239
@gialong1239 Жыл бұрын
idk how to create touchcontroll, can u help me =(((((
@xiennastudio
@xiennastudio Жыл бұрын
Hi, I explain about how to create Touch Control in this part 11:26. Remember to install Input System from Package Manager, and enable the Active Input Handling in Player settings to Both (06:32). Please tell me if you still have any issue :)
@gialong1239
@gialong1239 Жыл бұрын
@@xiennastudio hi....now i have a warning like this: "Saving has no effect. Your class 'UnityEditor.XR.Simulation.XREnvironmentViewManager' is missing the FilePathAttribute. Use this attribute to specify where to save your ScriptableSingleton. Only call Save() and use this attribute if you want your state to survive between sessions of Unity. UnityEditor.XR.Simulation.XREnvironmentViewManager:OnDisable () (at ./Library/PackageCache/com.unity.xr.arfoundation@5.0.7/Editor/Simulation/XREnvironmentViewManager.cs:169)" and my simulator can't work....sorry, this is my first time with unity and AR =(((((((
@xiennastudio
@xiennastudio Жыл бұрын
Hi, I'm sorry, I just noticed your comment. If you still have the issue, may I know the step-by-step that you did before getting this error? Did you follow my Basic Setup video or do you use the Unity AR template or you already have the project?
@IberianInteractive
@IberianInteractive 9 ай бұрын
Hello!! Any ideas why my prefab takes up the whole screen?
@xiennastudio
@xiennastudio 9 ай бұрын
Hi! By takes up the whole screen do you mean it's so big that it's covering your screen? If that's true, tried to change the prefab scale to be smaller.
@IberianInteractive
@IberianInteractive 9 ай бұрын
@@xiennastudio but why does it happen if i followed the same steps as you?
@xiennastudio
@xiennastudio 9 ай бұрын
Is your prefab scale is set the same as in the video? In 01:54 I set the scale to 0.1@@IberianInteractive
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 12 МЛН
I run untested, viewer-submitted code on my 500-LED christmas tree.
45:17
Coding INDOOR NAVIGATION with A* Pathfinding
10:24
MatthewHallberg
Рет қаралды 188 М.
Unity AR Foundation Tutorial - Tap to Place Objects in AR
13:43
Dinesh Punni
Рет қаралды 92 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 717 М.
Augmented Reality (AR) tutorial for beginners using Unity 2022
32:11
Playful Technology
Рет қаралды 301 М.