Social VR

Disaster Syndrome - Rope physics

Gabriel Brasil and Michael Fuller's amazing VR adventures! Today, we tried OBI Rope physics plugin in Unity together with VR controllers and it was a success! VR High fives for everybody!

NYU / ITP

November 10, 2018

Class: Desert of the Real - Deep dive in Social VR

Instructor: Igal Nassima

DISASTER SYNDROME – 2018 11 08

Created a new Unity Project named “Disaster Syndrome”.

Setup SteamVr and its basic interactions for our first scene.

GOALS 1: create two networked characters and create the rope dynamics interactions

OBI Rope Asset

We bought the OBI Rope Particle at the Unity Asset Store, as recommended by our instructor Igal.

OBI Rope comes with several solutions for our Rope dynamics.

Goal 1.1: Use OBI Rope plugin in conjunction with steam vr.

Obi is a collection of particle-based physics plugins for Unity. That means that everything is made out of small spheres called particles. Particles can affect each other, affect and be affected by other objects all through the use of constraints.”

“Obi only takes care of particle allocation and constraint setup. The physical simulation itself is performed by Oni (japanese for "demon") which is a completely engine-agnostic particle physics library written in C++. You can think of Obi as the middle-layer between Unity and Oni. Let's take a look at Obi's component architecture, and why it's made that way…”

Looked at OBI webpage for manuals and tutorials on setting up the plugin

 

Goal 1.1 achieved!: It works!

We started with the Obi Rope sample scenes, looking at each of different mechanics available. The Rope Chain scene has a chain attached to one Cube object that can be controlled by the user in the Scene window, and at the other end of the chain there is a big ball. When the Cube is moved, the chain and the ball move accordingly, knocking down physics objects in the scene.

After playing with the scene, we copied it and added the Steam VR plugins to it: Teleporting; Player; Teleport Area; Interactables and Throwable.

The goal was to attach the chain link to a throwable object,

First we just made the original chain Cube a child of the hand, but it couldn’t be thrown and the pivot point was far away from the hand/controller position.

Our second test involved adding Steam Vr’s “Throwable” and “Interactable” to the Cube attached to the chain. This made the cube move erratically on the scene, apparently “running” away from my hand. It was funny, but not what we are looking for.

Third was the charm, when we created a new throwable object “Capsule” and just added the “Obi Particle Rendered” and assigned the “Obi Chain” object/actor to it.

The Sphere was positioned on a platform since I couldn’t physically reach it on the floor (wonders of VR). In a moment the reminded us of Raiders of the Lost Arc, I carefully approached the “Capsule” and it remained attached to the chain and the ball. When thrown, it worked: The Capsule dragged the chain and the sphere with it.

Desert of the Real - Create a VR paintbrush

This is a 3-week-old assignment that I didn’t manage to do until now. The goal is to create a VR painting program.

Everytime I start to code I just freeze looking at the empty script. I just don’t know how to organize my thoughts and don’t have a clear idea of what is to be achieved. For this reason, I decided to write everything I want to do in plain English.

Before coding I set up the scene using the basic SteamVr package. I set up a Teleport area for locomotion; a plane to make this area visible; a cube platform to set my objects and for orientation; three cubes prefabs, each with a different material/color (red, green and blue) and finally a SteamVR player controller. I also put some throwable objects just to test the controller responsiveness.

The class template has an empty object called “InteractiveObject” where the BrushHandler and ColorSelector scripts are kept. The ControllerHandler script is found in the Players “RighHand”.

 

 

 

Now for the coding part:

Goals:

·       Have a Brush object

·       The brush is controlled with the VR controller.

·       Have colored objects on the scene that will serve as colorPalette.

·       When Brush touches one of these objects – it changes to the objects color.

·       When pressing the Trigger Button on the controller, the Brush creates many copies of itself named paintObjects, allowing to paint the scene with it.

·       The paintObject must have the color of the brush.

·       If the brush touches a colorPalette with a different color, it should change color but the paintObject already on the scene should remain with its original color – Once paint is set, it should remain the same color. (no changing the color of what was already drawn)

·       There should be a limit on how many paintObjects are on the scene at any given time:  a limit on how much paint can be on the scene. If this limit is reached, the ‘oldest’ paintObject must be deleted.

·        

 

There are three scripts already created by the class instructor Igal Nassima. They come with comments and guidelines, but I don’t really understand his workflow. I’m not sure where Igal want us to set the scripts; if the Brush object is created by the script or if it will already be on screen.

I will try to do it somehow…

·       ControllerHandler

o   Makes the brush paint

o   Checks what color is in the brush

o   Get the brush color

o   Creates instances of the paintObject that has the current color of the brush.

·       ColorSelector

o   “Create a public Color Type that can be set from the inspector to be used in each menu Item” – (comment by Igal) – Don’t understand what he means by “color type” and why it must be set from the inspector.

o   “Setup Collider Trigger to send the color of this object to the Brush Handler” – Checks if there is a collision between the brush and another object and send the color of this other object back to the Brush Handler.

o   “Find Object of Type à then call the function that sets the currentColor” –

·       BrushHandler

o   Store the current color on the brush

o   Sets what gameobject will be drawn/created/instantiated when activated by the trigger on the controllerHandler.

o      //create a public function that SETS UP the color of the currentColor (hint, function must have a Color variable)

o       //create a public function that RETURNS the Color of the currentColor

§  Don’t know the difference between Set UP the color and “Returns the Color” and what it is supposed to do..

§  Also, Don’t know how to make scripts communicate with one another.

Found an example at my colleague Ellen Nickles documentation of this assignment:

//Inside the ControllerHandler script it calls the the color on BrushHandler:
  private void OnTriggerEnter(Collider other)

    {

        FindObjectOfType<BrushHandler>(). currentColor = myColor;

    }

 

 

 

Creating the Brush

The Brush doesn’t paint, but stores its own color and changes color when

·       The brush is a Sphere prefab named ‘Brush’.

·       It will have a color.

·       It will get the color of the object it touches

·       It will return the color it has

·       It has a script called BrushHandler. It will set the following behaviors:

o   Stores the currentColor

o   Creates/Returns the prefab that will be drawn (the “paint”)

 

Starting to write the code itself

              Don’t really know where to start. I look at the three template scripts, but don’t know which function to make. I don’t even know if I should create the brush object of if it is instantiated by one of the scripts.

 

Instantiation Tests

In order to practice basic coding, I also created a Test script to try things out.

I created a transform function that makes a cube move and it asks for a GameObject. I added a different object on the inspector but the object where the script was attached – the cube -  still was the one that moved. Why?

1 Creating – Instantiating an object

              I will create a brush and make it instantiate copies of itself when user press the Oculus Controller Trigger button. I’ll figure the other actions (changing color) later.

              We managed to run a basic instantiate code copied from the Unity API manual. At first it didn’t worked, because we added the script to the prefab we wanted to instantiate. This freezes Unity because it was trying to instantiate the object WITH the instantiate script. Once we added a different prefab to the public GameObject slot in the Inspector the instantiate code worked fine.

Basic Unity Instantiate example 1:

//The Manual didn’t used “public”.  

 public Transform prefab;

    void Start()

    {

        for (int i = 0; i < 30; i++)

        {

            Instantiate(prefab, new Vector3(i * 2.0F,i* 1, 0), Quaternion.identity);

        }

    }

Basic Unity Instantiate example 2:

public class TestScript : MonoBehaviour

{

    // Instantiate a rigidbody then set the velocity

 

    public Rigidbody projectile;

 

    void Update()

    {

        // Ctrl was pressed, launch a projectile

        if (Input.GetButtonDown("Fire1"))

        {

            // Instantiate the projectile at the position and rotation of this transform

            Rigidbody clone;

            clone = Instantiate(projectile, transform.position, transform.rotation);

 

            // Give the cloned object an initial velocity along the current

            // object's Z axis

            clone.velocity = transform.TransformDirection(Vector3.forward * 10);

        }

    }

}

 

STARTING FROM SCRATCH (?!!)

                  For some reason it seems that SteamVr plugin is no longer functional on my project. I can’t find the Steam Controller Input inside the ‘Window’ menu. I downloaded the template project again and it seems to be working fine there. I’ll have to setup my scene again.

Update: Maybe the SteamVR plugin wasn’t turned on (for some reason). I started a new project anyway.

 

 

 

Spheres everywhere! Instantianting is a success (and out of control)

Spheres everywhere! Instantianting is a success (and out of control)

Making the paint brush:

Now we have two scripts that allows us to create spheres on the scene. One creates on sphere at every frame and other creates one sphere when “Fire1”/ Ctrl is pressed on the keyboard.

By changing the prefab instantiated by theses scripts it was possible to create a static sphere on the scene – one that has no gravity or doesn’t fly away. By pressing “Fire1”/Ctrl it was possible to create flying sphere and ‘paint’ the scene with spheres.

Goal:  Create static instances of a sphere while the Oculus Controller Trigger button is pressed and stop creating when not pressing.

`This is the code created

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class DrawTest : MonoBehaviour

{

public Transform paint;

void Update()
{

    if (Input.GetButtonDown("Fire1"))
    {

        createPaint();
    }

}

void createPaint()

{`

        for (int i = 0; i < 1; i++)
        {

            Instantiate(paint, transform.position, transform.rotation);

        }

}

}

 

This script works like the first one: It creates one sphere every time “Fire1”/Ctrl is pressed, but it doesn’t keep creating more balls if the button is still pressed. Maybe I need to change “Input.GetButtonDown” to something else…

Changed from “Input.GetButtonDown” – that returns true when the button is pressed down and only resets if released – to “Input.GetButton” – that returns true every frame the button is pressed. And it works!

Nice smooth sphere paint created on the scene.

Nice smooth sphere paint created on the scene.