"Getting Started with Meshing..." Examples Not Provided

“Getting Started with Meshing in Niantic Lightship” is the second video on the Lightship AR playlist. It opens up almost immediately with the narrator showing a canvas with a shoot button that they have already prepared. They then say that’s all they have prepared, but a few seconds later they add a ShootProjectiles script that they also prepared before shooting the video. Later, we also see different meshes that they have also created and are using for the tutorial.

Not having all the tools available to follow along is pretty frustrating. I get that it could be easy for viewers to create these examples, but then they are focusing on creating Unity mechanics, instead of spending their time learning about the ARDK.

Please consider using examples where everything is shared so that we can get to creating faster!

Thanks

3 Likes

Hi John, thank you for your feedback! We will forward this to our team.

1 Like

Hi John, narrator here!

The walkthough videos are a first pass at an overview of the ARDK in 10 minutes or less, and it’s true in writing mine I assumed an audience of Unity developers, that’s why I didn’t go over how to set up a basic UI or a basic script.

For creating the button, here’s a good resource: Creating UI Buttons - Unity Learn

And for the script, here’s my script. It’s not optimized code (instantiating that many objects from a prefab will noticeably hurt performance), but I hope it can serve as a starting point!

using System.Collections.Generic;
using UnityEngine;

public class ShootProjectiles : MonoBehaviour
{
    /// Prefab of the projectile to be instantiated. Must contain a Rigidbody.
    public GameObject _projectilePrefab;
    /// How many projectiles to instantiate every time we shoot.
    public int _projectilesPerShot = 7;
    /// How much force to apply to each projectile when firing.
    public float _projectileForce = 1.0f;
    /// How scattered from the center each projectile fires (0 = straight, 1 = 45 degrees)
    public float _shotSpread = 0.2f;

    private struct ShotInfo
    {
        public GameObject _prefab;
        public Vector3 _origin;
        public Vector3 _force;
    }

    private Queue<ShotInfo> _shotQueue = new Queue<ShotInfo>();

    void Update()
    {
        foreach (Touch touch in Input.touches) 
        {
            if (touch.phase == TouchPhase.Began)
            {
                Shoot();
            }
        }
    }

    private void FixedUpdate()
    {
        if (_shotQueue.Count > 0)
        {
            Fire();
        }
    }

    public void Shoot()
    {
        QueueShots();
    }

    private void QueueShots()
    {
        var forward = transform.forward;
        var up = transform.up;
        var right = transform.right;

        for (int i = 0; i < _projectilesPerShot; i++)
        {
            var upVal = _shotSpread * Mathf.Sin(Mathf.PI * 2 * i / _projectilesPerShot);
            var rightVal = _shotSpread * Mathf.Cos(Mathf.PI * 2 * i / _projectilesPerShot);
            var force = (forward + upVal * up + rightVal * right).normalized * _projectileForce;
            
            ShotInfo shot = new ShotInfo();
            shot._origin = transform.position;
            shot._prefab = _projectilePrefab;
            shot._force = force;
            _shotQueue.Enqueue(shot);
        }
    }

    private void Fire()
    {
        var shot = _shotQueue.Dequeue();

        if (!shot._prefab) return;
        
        var projectile = GameObject.Instantiate(shot._prefab, shot._origin, Quaternion.identity);
        var rigidbody = projectile.GetComponent<Rigidbody>();

        if (!rigidbody)
        {
            Destroy(projectile);
            return;
        }
        
        // Apply force
        rigidbody.AddForce(shot._force, ForceMode.Impulse);
        Random.rotation.ToAngleAxis(out float _, out Vector3 axis);
        rigidbody.AddTorque(axis);
    }
}

4 Likes

Anthony,

Thank you so much for responding! The videos you and the rest of the team have made are amazing.

Personally, I followed your lead and wrote a quick script to fire some objects that could bounce around my mesh and eventually settle down. The reason I posted my request is because I want to help make sure that everyone who wants to learn about Lightship has a smooth experience. I think the best way to make that happen is to keep the viewers locked in on Lightship content and not have to worry about anything that they aren’t being presented with. The ARDK makes things so simple that it’s easy to crank through the examples. I just figured this was an oversight based on how effortless all of this has been made for us by Niantic.

In the spirit of thinking about the next person through the video track, I would recommend either adding your shoot script and yeti rigidbody either to the ARDK-Examples bundle or a link in the description of the video. Just a thought!

Thanks again and keep up the great work!

2 Likes