Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Can't get Camera point to ray in Tiny

Discussion in 'Project Tiny' started by MAyahmay, Jun 22, 2020.

  1. MAyahmay

    MAyahmay

    Joined:
    Jun 22, 2020
    Posts:
    5
    I try to use Raycast for Getting mouse click on object but I try to use old Camera ScreenPointToRay but it seems this method not work in dots environment, I try to get camera entity but I can't find ScreenPointToRay function in it.
    I want to know how do I spouse to get Mouse click Raycast in Tiny ?!
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Correct you can't use ScreenPointToRay from the classic Unity
    You can either
    Check our RuntimeGeometry3D sample we do use ScreenToWorld system
    https://github.com/Unity-Technologi...ometry3D/Assets/Scripts/GeometryMainSystem.cs

    Or use Raycast from Unity.Physics https://docs.unity3d.com/Packages/com.unity.physics@0.0/api/Unity.Physics.RaycastHit.html I think there is a sample in this project https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/UnityPhysicsSamples that uses physics raycasts
     
    MAyahmay likes this.
  3. MAyahmay

    MAyahmay

    Joined:
    Jun 22, 2020
    Posts:
    5
    Thanks for guide.
    I could use Raycast from Physics but I couldn't use ScreenToWorld in my project it can't find any class or resource with that name.
     
  4. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    maybe do something like

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using Unity.Tiny.Input;
    4. using Unity.Transforms;
    5. using Unity.Tiny.Rendering;
    6.  
    7. public class MySystem : SystemBase
    8.     {
    9.         protected override void OnUpdate()
    10.         {
    11.             var input = World.GetExistingSystem<InputSystem>();
    12.             var s2w = World.GetExistingSystem<ScreenToWorld>();
    13.             var inputPos = input.GetInputPosition();
    14.             float3 pos = s2w.InputPosToWorldSpacePos(inputPos, 4.0f);
    15.             // Do whatever with pos
    16.  
    17.         }
    18.     }
    make sure to add
    "Unity.Tiny.Input",
    "Unity.Tiny.Rendering.Native",
    "Unity.Tiny.Rendering",
    to your asmdef references
     
  5. MAyahmay

    MAyahmay

    Joined:
    Jun 22, 2020
    Posts:
    5
    I got error when Calling s2w.InputPosToWorldSpacePos.
    I make a new thread with bug tag to it.
    https://forum.unity.com/threads/screentoworld-system-error.923936/