In this assignment, to be completed in class, you will make the cubes move and explode.
Open the Unity project you started for homework 1. Go to the scene where you made your lightsaber, and make your lightsaber into a prefab. (Drag it from the scene into your Projects view). Now that you have the lightsaber as a prefab, you can easily place it into other scenes.
Now, please download our starter package here. Go into your Unity and at the top hit Assets -> Import Package -> Custom package, and select the package you just downloaded.
Open up the RHVRGoCameraRig prefab and find the right hand controller. Move your lightsaber (the cylinder we made last week ) under the OculusGoControllerModel.
Make sure your lightsaber has a Capsule Collider with Is Trigger checked, a Rigidbody
with Use Gravity UNchecked and Is Kinematic checked, and a
SaberControl
script.
Adjust your lightsaber's transform so it looks aligned with the controller. My values are:
Position: X: 0 - Y: 0.68 - Z: 1.88
Rotation: X: 70 - Y: 0 - Z: 0
Scale: X: 0.1 - Y: 2 - Z: 0.1
Create a new script called MoveTransform
and put it in your "xScripts" folder.
Create two variables: Vector3 moveDir
and float speed
and make them private
and use [SerializeField]
for both variables.
Private variables are only accessible within the class, which keeps it safe from hard-to-track external modifications.
It is a standard coding convention to keep variables private unless it is necessary for public access.
[SerializeField] exposes the variable value in the inspector.
In the Update loop type transform.Translate(moveDir * speed);
.
HW QUESTION: What do you think Translate does? What are moveDir
and speed
?
Create an empty object named ObstaclesParent and give it some cubes as children. (In the screenshots, it is called "CubeCircle"). Select the ObstaclesParent object. Attach the MoveTransform
script to the ObstaclesParent
object by dragging it onto the inspector.
On the MoveTransform script, set the Move Dir
Z to -1. Set the Speed
to 0.05. Hit Play.
Move the ObstaclesParent object back on the z-axis so it is far away from the camera.
Hit play.
Go into the ObstaclesParent object and make more cubes that are spread out, but make sure they are narrow. Adjust the speed to your liking, 0.05 is normal, but 0.1 is harder.
Assignment written by Khoi Le, Ethan Aldrich and Connor Settle, October 2018 with contributions from Jerry Meng.