VR Physics Simulation
This is my first introduction level learning project in VR development. The main idea is to create a simple but realistic VR simulation of an air vehicle that actually takes into account laws of physics. For example the acceleration and maneuverability will be different for a vehicle with smaller mass and a vehicle with higher mass. Relevant parameters are visualized in real time and the sim can be viewed in HTC Vive.
1.) Decide betw Unity and UE and go through an intro lesson w the tool
2.) Pick 2-3 similar projects done and get familiar w used physics tools
3.) Find a vehicle or create your own, doesn't have to look nice yet
4.) Flight controls and input param, explain what can be changed and what not
5.) Can you visualize and change the air flow - show and explain the answer
6.) Vehicle ready and flying, acceleration, roll, pitch, yaw realistic
7.) Visualize physics data, mass, speed, roll, pitch, yaw. Looks nice.
No idea how to visualize things for Vive or how much time it takes. Also don't know how much of any physics parameters can be changed. For example vehicle's mass or gravity. My biggest concern is that I will spend 3-4 times more on each step than I imagine and new necessary steps will add on the run that I didn't know about. I have almost no experiences in programming so I expect to have some difficulties here too. But I'm motivated to learn when I can visualize it.
What I want to learn
I want to know how to make realistic movement simulations considering laws of physics, what parameters can and cannot be tweaked in the used tools, and in overall, get familiar with VR development tools. The most complex takeaway for my next project is how to control movement of a body with some mass, in a certain gravity environment.
Milestone 1 (02.03)
- Development environment is chosen and first lesson done how to use the tools.
I need to choose between Unity and Unreal Engine. I saw a small glimpse of Unity 6 months ago when I did an intro Roll-a-ball tutorial from Unity homepage (https://unity3d.com/learn/tutorials/s/roll-ball-tutorial). To get an intro to Unreal Engine (UE), I attended to APT Game Generator UE workshop. The workshop was for beginners and lasted ca 2 hours. We didn't do much but at least I saw the tool and some of its usage. After asking and searching around, I chose Unity. For now. For this project. No particular reason, just had to decide. Both tools are good according to people who use them. Both tools enable to develop simple and complex stuff. Both are more than enough for my project. No serious and reasonable advantages found.
So it's Unity. Ver. 2017.3.1f1 Personal.
Tutorials I did:
Unity for Absolute Beginners Lesson 1 - Moving, Rotating, Resizing objects (8 min 25 s):
Unity for Absolute Beginners Lesson 2 - Rotate object with code (13 min 58 s):
After above tiny tutorials, I feel surprisingly comfortable with creating a plane (floor plane, not an air vehicle) and a ball, moving, rotating and resizing them. Much better than the long tutorial I tried long ago. The short tutorials seemed more efficient to me. Got me going faster, there were less things to remember at once and I didn't lose my focus like with long tutorials. Currently, I am happy with choosing Unity.
Regarding physics, I have already seen that in the working environment, you can set a mass for an object. This is possible in both, Unity and UE, and it's available right in the start, in a handy and visible settings location, as soon as you create some object and see the Inspector layout. Good. Before that, I thought that physics parameters are all either preset or hidden as far as possible from the user so it doesn't scare them off. It's good that I was wrong. My project has hope.
Time consumption, approx:
Workshop 2 h + Unity vs UE searching and asking 0.5 h + tutorial videos 0.5 h + organizing stuff like finding tutorials, making notes etc. 0.5 h = 3.5 h
Milestone 2 (16.03)
- Few similar projects found and explored. Learned physics tools to demo 2 different gravities.
First about the physics tools. You can set gravity in your Unity project settings (Edit > Project Settings > Physics). In the Inspector tab there is y-coordinate Gravity setting which is by default -9.81 (ms-2). You can edit it. So I learned that you cannot just set one gravity setting to some plane1 and a different one to some plane2 inside one project. Makes sense. For now. If I want to show different gravities in one project I need to play with the object's counterforce that acts on the gravity. About that I found useful info from:
Unity 2017 Beginner Tutorial 4 - Physics, Gravity, Jetpack effect (13 min 15 s):
Alternative option to have two different gravities is to make a gravity variable in your ball script code, duplicate your ball and set different values to each ball's g var. This I learned from smarter people in the class. Very simple!
I also learned that in object Transform settings where you can set position in all 3 axes, for example nr 1 corresponds to 1 m in the game and by default the speed of moving object (for example a ball) is 30 fps so if you set y to 1 and assign a keyboard key to move the ball to this direction, the ball will move 30 m/s. This is too fast for learning how to move stuff around! So try 0.1f first. It will be a float and results in 3 m/s. Looks OK for learning.
Another thing I learned is that if you made a script for your plane to move with arrow keys, you don't have to delete or comment out this script to move some other object with arrow keys. Just disable the plane moving script from a ball object script for example. And then write some code to move the ball. For now, for learning and experimenting, this is useful knowledge.
C# example to disable planeControl script from ballControl script:
GameObject varGameObject = GameObject.Find("Plane"); varGameObject.GetComponent<planeControl>().enabled = false;
Plane is my plane object and planeControl is my plane control script. This code needs to be run only once so it's located under void Start() method. Not under void Update().
One of my favorite project examples is still this:
It's done in UE4 but it doesn't matter. I will still try to achieve some of this in Unity. Controlling the flight with some small thrust settings is an interesting thing to try. The physics of a thruster is very cool.
Milestone 3 (30.03)
Milestone 4 (13.04)
- Replace a ball with some vehicle (doesn't have to look nice yet) and use 3 axis for flight movement
Downloading some ready made vehicle was not what I wanted to do. Because it's too easy. I wanted to know what can be done in Unity and what not. So I decided to make my vehicle using Unity standard 3D object Cube only. Something very simple, to see how add objects together and make them move together, not more.
Inspiration video - The making of the Jet Physics Model in Aircraft Flight Physics Toolkit for Unity 3D (5 min 36 s):
At least I got the point that it CAN be done, with an effort :) I learned that if you want to make several objects move as one, you simply create for example 5 cubes, choose one to be the parent and add the rest under this parent. Just drag them on the parent and that's it. My result, very basic, can be seen below. But it raised questions. Like what happens to the mass of the final parent object? For my 5 cubes it's still 1. But what if I want to make building blocks that each have the mass of 1 and add them together by adding also the masses together? Anyway, I also got the point that my next vehicle will be done using some dedicated SW, or downloaded, if I find something really cool already done by others.
Second thing I learned is the pain of making an object fly using 3 axis and the keyboard for control. That outcome I did not like. Many tutorials out there. Watched also several videos. From which many use ready made scripts from AssetStore, to control some cool aircraft movement. But for studying different ways, I stuck with basic Unity code tools and just played around with some approaches. For example transform.Translate(x, y, z) using Input.GetKey(). Or using Vector3 movement with horizontal and vertical but no 'Z' axis. Or combination of those two and adding transform.Rotate(). I still need to figure out what I need for which purpouses!
And I also switched from MS Visual Studio to MonoDevelop (integrated with Unity) because it appeared that Visual Studio had a trial period, it ended, and I did NOT want to sign in with any MS account to keep using it for free. MonoDevelop is ok.
Milestone 5 (27.04)
- Flight controls using different input param (mass, acceleration) for 2 different vehicles.
This one was difficult. After 7h of work I made a new ship, tried several movement code examples, tried to multicolor my new ship, played around with objects' parenting and... Unity crashed. My new ship is gone. So I took my previous tiny ship. Duplicated it. For different mass settings. And focused on code only. Problems:
1. AddForce on key press seem to work but can't figure out how to use AddTorque together with it to turn my ship in flying direction. All examples I found use Transform. And AddTorque examples don't use AddForce with flight controls.
2. One ship mass is 10 kg and the other is 100 kg. When I change the drag, they fly differently and almost ok (heavy ship responds slower) but after adding new 3d objects (they are not even related to ships yet) they don't fly anymore but fall down. Why on earth? Can't figure out what happened.
3. I wanted to add black color sphere to one ship and blue color sphere to the other ship. To distinguish them by weight and to mark the top of the ship so you know which side is up. But when I make the colored sphere and finally want to add it to the ship as a child, the sphere changes shape and turns into a weird blob. No modification of it's size fixes it. Why?
I'm puzzled and have not achieved my milestone in the time I had :(
From ca 20 different Youtube videos I found those the most useful:
Tutorial Unity3d Flying Drone 2.1 - Levitating/Up/Down movement (7 min 35 s):
Tutorial Unity3d Flying Drone 2.2 - Forward Movement & Tilting (6 min 22 s):
Tutorial Unity3d Flying Drone 2.3 - Rotation (5 min 59 s):
Milestone 6 (11.05)
Problems understanding 3D movement controls in Unity :(
Milestone 7 (25.05)
- M5 fixes + initial demo ready in VR. With VIVE or Xbox controllers.
- Final build for 25.05 presentation: https://drive.google.com/open?id=1QAqGPS3PWitzugCB9zEN6pnimGVTGwpT
The result for the final project presentation was modest. There is a green plane (ground), two 1x1x1m white cubes just for reference, one big wall to fly around (or into) and 3 funny shaped ships with different masses. One ship is with suitable mass for flying and during flight, three force vectors appear in red when controls for roll, pitch or yaw are used. For easy and slow flight, during presentation, gravity was disabled. Best experience for me was Oculus Rift headset + Xbox controller.