commit 9021662dd8923c9f186bb41d28e656e7a55cd40b
parent 2470e9388c1c5bab6e7fb35ec34c943fca217038
Author: Andrew <andrewlaack1@gmail.com>
Date: Tue, 16 Apr 2024 16:32:07 -0500
Completed W12 l1 for cs331
Diffstat:
7 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/GameLoop.md b/GameLoop.md
@@ -9,4 +9,6 @@ CS 331 W12 L3
This is the same idea as animation which is giving motion to still images.
+When using the game loop you can call Time.deltaTime to get the seconds between the previous and current frame as a float. This can be used to achieve frame rate independence.
+
See [[MonoBehaviour.md]] for more about update method.
diff --git a/GameObject.md b/GameObject.md
@@ -6,3 +6,13 @@ CS 331 W12 L3
## Notes
**Definition:** This is the data type of objects in the game. This is a broad class that has some built in functionallity.
+
+A common way to move an object forward using it's [[Vector3.md]] is as follows:
+```csharp
+ float speed = 2; //default forward speed
+ bool moveForward = Input.GetKey("up");
+ if(moveForward){
+ transform.position += transform.forward * speed * Time.deltaTime();
+ }
+
+```
diff --git a/Input.md b/Input.md
@@ -0,0 +1,14 @@
+# Input
+
+CS 331 W12 L1
+
+## Notes
+
+**Definition:** Input is the class used the get input from the user.
+
+### Common Methods
+
+1. GetKey
+ - This returns true if the key is pressed
+ - Ex. bool moveForward = Input.GetKey("up");
+2.
diff --git a/Movement.md b/Movement.md
@@ -0,0 +1,34 @@
+:cs331: :unity:
+# Movement
+
+CS 331 W12 L1
+
+## Notes
+
+There are many different ways to implement movement.
+
+A common way to move is by doing this:
+
+```csharp
+
+float speed = 2.0f; //assign default movement speed
+float rotationRate = 10.0f; //assign default rate of rotation
+
+bool moveForward = Input.GetKey("up");
+if (moveForward){
+ transform.position += transform.forward * speed * Time.deltaTime();
+}
+
+bool rotateLeft = Input.GetKey("left"); //this assumes rotation is done by keyboard input
+if(rotateLeft){
+ transform.Rotate(0, rotationRate * Time.deltaTime(), 0);
+}
+```
+The issue with this is movement may not feel natural because there is no acceleration being applied to the object you are just moving it by a certain amount. In essence, you are assigning a velocity to the object for the frames where the "up" key is pressed.
+
+
+See [[Input.md]] for more information about the Input class.
+
+See [[Vector3.md]] for more information about positions.
+
+See [[Quaternions.md]] for more about rotation/angles
diff --git a/Transform.md b/Transform.md
@@ -11,7 +11,14 @@ In Unity, we have a left handed coordinate system as oppossed to the standard ri
Additionally, each game object has its own local coordinate system that moves with the object. In this way Z becomes forward, X becomes right, and y becomes up with respect to positive values on said axis.
-The datatype used to represent position in 3d space is Vector3. Each x,y,z component is of datatype float.
+The datatype used to represent position in 3d space is [[Vector3.md]]. Each x,y,z component is of datatype float.
See [[Quaternions.md]] for rotations.
+Object is transform while the datatype is Transform.
+
+Transforms have the following public members:
+
+1. position (Vector3)
+2. rotation (Quaternion)
+:todo: find the rest I think scale is included
diff --git a/Unity.md b/Unity.md
@@ -36,4 +36,6 @@ Unity is a popular game engine, no duh.
[[MonoBehaviour.md]]
[[Lighting.md]]
[[GameLoop.md]]
-
+[[Vector3.md]]
+[[Input.md]]
+[[Movement.md]]
diff --git a/Vector3.md b/Vector3.md
@@ -0,0 +1,10 @@
+:unity: :cs331:
+# Vector 3
+
+CS 331 W12 L3
+
+## Notes
+
+**Definition:** The Vector3 class in unity is used to represent x,y, and z coordinates in a singular object. This object stores each axis value as a float.
+
+See [[Movement.md]] for how to use Vector3s to move.