Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Help Wanted My Balls won't drop!

Discussion in 'Unity MARS' started by jaaronleesanderson, Jul 21, 2021.

  1. jaaronleesanderson

    jaaronleesanderson

    Joined:
    Apr 10, 2021
    Posts:
    2
    I have a simple project where I add a ball prefab when the user taps the screen. The project was working until I added Mars. Prefab has a rigid body and gravity is enabled. I think I must be missing a check mark somewhere. Any suggestions?
     
    hippocoder likes this.
  2. jmunozarUTech

    jmunozarUTech

    Unity Technologies

    Joined:
    Jun 1, 2020
    Posts:
    258
  3. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    139
    Hey there @jaaronleesanderson,

    I think we're going to need a bit more info to help you solve this issue. Are your ball prefabs showing up on screen and not moving? Are they not showing up at all? Can you try running your scene in Play Mode to see if you can see any changes in the hierarchy or scene view that look suspicious?
     
  4. jaaronleesanderson

    jaaronleesanderson

    Joined:
    Apr 10, 2021
    Posts:
    2
    The balls appear on the screen suspended in mid air above the quad placement indicator. In a previous version of the project without MARS the balls would fall. Now it just adds balls without them falling above the placement indicator. I'm also having an issue with the pose tracker. Code below.


    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.XR.ARFoundation;
    4. using UnityEngine.XR.ARSubsystems;
    5. using MoreMountains.NiceVibrations;
    6.  
    7. public class BallStackerAR : MonoBehaviour
    8. {
    9.     /// <summary>
    10.     /// Reference to the Raycast Manager
    11.     /// </summary>
    12.     ARRaycastManager raycastManager;
    13.     Camera arCamera;
    14.  
    15.     [Tooltip("The object to spawn when the screen is tapped")]
    16.     public GameObject objectToSpawn;
    17.  
    18.     void Start()
    19.     {
    20.         //Initialize private variables
    21.         raycastManager = GameObject.FindObjectOfType<ARRaycastManager>();
    22.         arCamera = GameObject.FindObjectOfType<Camera>();
    23.     }
    24.  
    25.     void LateUpdate()
    26.     {
    27.         //Figure out where the center of the screen is
    28.         var viewportCenter = new Vector2(0.5f, 0.5f);
    29.         var screenCenter = arCamera.ViewportToScreenPoint(viewportCenter);
    30.  
    31.         //Check if there is something in front of the center of the screen and update the placement indicator if needed
    32.         UpdateIndicator(screenCenter);
    33.  
    34.         //If we tap on the screen, spawn an object
    35.         if (Input.GetMouseButtonDown(0))
    36.         {
    37.             //Spawn the object above the floor to see it fall
    38.             Vector3 objPos = transform.position + new Vector3(0,1,0);
    39.             if (objectToSpawn)
    40.             {
    41.                 Instantiate(objectToSpawn, objPos, transform.rotation);
    42.                 print(Physics.gravity);
    43.                 MMVibrationManager.Haptic(HapticTypes.LightImpact);
    44.             }
    45.         }
    46.     }
    47.  
    48.     /// <param name="screenPosition">A position in screen space</param>
    49.     private void UpdateIndicator(Vector2 screenPosition)
    50.     {
    51.         var hits = new List<ARRaycastHit>();
    52.         raycastManager.Raycast(screenPosition, hits, TrackableType.Planes);
    53.  
    54.         //If there is Attribute least one hit position
    55.         if(hits.Count > 0)
    56.         {
    57.             //Get the pose data
    58.             var placementPose = hits[0].pose;
    59.             var camForward = arCamera.transform.forward;
    60.             //We want the object to be flat
    61.             camForward.y = 0;
    62.             //Scale the vector to have the size of 1
    63.             camForward = camForward.normalized;
    64.             //Rotate to face in fron of the camera
    65.             placementPose.rotation = Quaternion.LookRotation(camForward);
    66.  
    67.             //move Quad slightly to avoid z-fighting
    68.             var newPosition = placementPose.position;
    69.             newPosition.y += 0.001f;
    70.             transform.SetPositionAndRotation(newPosition, placementPose.rotation);
    71.         }
    72.     }
    73. }
     
  5. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    139
    Thanks for the information. Unfortunately I can't think of anything in MARS that would be interfering with Physics or gravity. Are you able to share your project using the bug reporter?
     
unityunity