I would like to create a placement indicator. To do this I have to make a raycast from the center of the camera in MARS simulation. How can I do this?
Hey @Goan123, so the easiest way to use the “MARS Plane Visualizer” and simply customize the “Plane Prefab” to support collision detection. Details below: First make your plane prefab (empty game object, then GameObject Menu / 3D Object / Plane to add a plane under it, use a material that repeats in the UV texture space). Now create a “MARS Plane Visualizer” (just add that component or choose: GameObject Menu / MARS / Data Visualizers / Plane Visualizer”, and set the “Plane Prefab” to the prefab you created above. At this point you should get planes that you can Physics.RayCast against to get collisions, and it should appear in the Simulation View as well. If you want your custom cursor code to also work in the Simulation or Device views, simply add the “Unity.MARS.ISimulatable” interface to your cursor behavior, and it will run in the Simulation Scene, as well as in Play mode.
By the way, to put a proxy into the center of the view you can also use Forces, get a proxy that spawns onto horizontal plane, then select "Forces / Add Force..." in the Inspector and add "Align to Camera", as well as "Snap to Horizontal/Vertical Surface". This is for play mode, but will influence the object to be centered in front of your user, and on a surface (it's not as 100% as ray casts, but easier to setup).
Following up on @leweyg_unity reply, you could check the docs for forces at: https://docs.unity3d.com/Packages/com.unity.mars@1.0/manual/Forces.html we have a tutorial and a quick getting started session
See this thread: https://forum.unity.com/threads/mars-direct-placement-example.908381/ for a template that adds placement via raycasting with an indicator.
Is there a way (existing template?) to have MARS adapt to what ARKit would behave/do for plane finding / mesh classification?
Was hoping Unity MARS could fully simulate ARKit environments for in-editor testing. However, after fiddling quite a bit and watching all the tutorials and reading the docs, I cannot seem to get raycast hit to return (also, there just aren't enough people using it in the community yet - something as basic as this shouldn't be so obscure). So I am just going back to the indie solution - ARFoundation Remote https://assetstore.unity.com/packages/tools/utilities/ar-foundation-editor-remote-168773
Re raycasting: If you are using regular Unity physics raycasting then if you add a mesh collider to the prefab that the plane visualizer uses then you should get hits. If you are using the MARS IUsesMRHitTesting interface and not getting hits that's a known issue that we are working on.
And on the subject of AR Foundation simulation, as of MARS 1.2 (released last week) we do support simulation for AR Foundation in the editor. This is a very new feature and not everything is supported yet, but we'd love to have you try it out and give us feedback. If you get MARS 1.2 and enable it in Project Settings > XR Plug-in Management then when enter play mode you should be able to test AR Foundation scenes against MARS's simulation environments.
Thanks for the reply. So I tried that - *visibly* ticking that MARS Simulation checkbox in XR Plugin-Management... but I am still not getting a raycast return? I am using ARFoundation's ARRaycastManager. Raycast returns on actual device and using the indie creator's ARFoundationRemote from the Asset Store
I am just using ARRaycastManager - which returns on both device and on ARFoundationRemote... I have yet to be able to get raycast to work on MARS https://docs.unity3d.com/Packages/c...yEngine.XR.ARFoundation.ARRaycastManager.html Also, I notice that in Simulated Environment scene, the Kitchen_13ftx9ft includes colliders... Does MARS only work with Physics.Raycast? Why isn't Unity's own ARFoundation supported?
That's not good - it should work When you enter play mode has MARS discovered the planes - if you add a plane visualizer is it showing planes where you are raycasting?
Can you let me know if there are only certain versions that this works on? What is the tested / recommended MARS, AR Foundation, Unity version?
Should work with any versions that MARS supports. I just tested Unity 2019.4.16f1 with AR Foundation 2.1.10 and MARS 1.2. Do you have a scene or project you can share?
hello @chanfui, if by files you mean the direct placement example, they are here: https://forum.unity.com/threads/mars-direct-placement-example.908381/
Hi, In relation to this post (https://forum.unity.com/threads/depth-calculation.1073873/), I have been trying to get the distance from a ray shot from the centre of the screen (ie. device) to a surface in the real world. I have tried replacing the prefab of the planes visualiser but I am still getting null results in play mode. I am using the following script (attached to an empty game object in the MARS scene). Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.ARFoundation; using UnityEngine.XR.ARSubsystems; public class RaycastLiDARHandler : MonoBehaviour { private ARRaycastManager arRaycastManager; private static List<ARRaycastHit> hits = new List<ARRaycastHit>(); private Vector2 rayPos = new Vector2(Screen.width/2, Screen.height/2); private float distance; void Start() { } void Update() { //if (arRaycastManager.Raycast(rayPos, hits, TrackableType.Planes)) if (arRaycastManager.Raycast(rayPos, hits)) { distance = hits[0].distance; print("DISTANCE: "+distance); } } }
I think you're getting null reference errors because arRaycastManager is never initialized. If you add an AR Raycast Manager component to the MARS Session (it wants to be at the session origin) and then reference it in your script (I just made arRaycastManager public and dragged the session to it in the editor) it should work.