Game Dev
Game Dev
Student name:
2. To make the game independent of the speed of the system on which it runs:
a) Use higher level libraries
b) Use mathematical optimization functions
c) Use a time step proportional to frame rate
d) Use a time step inversely proportional to frame rate
Page 2 of 7
Question 2 [35 pts]: Write the pseudocode of a script that does the following:
1. Create a cylinder and a cube. Position and scale as shown in the figure.
1.
GameObject cylinder;
GameObject platform;
Start(){
cylinder = GameObject.CreatePrimitive(Cylinder);
platform = GameObject.CreatePrimitive(Cube);
cylinder.transform.position = new Vector3(0, 0.5, 0);
cylinder.transform.scale = new Vector3(1, 3, 1);
platform.transform.position = new Vector3 (0, 0, 0);
platform.transform.scale = new Vector3 (10, 0.5, 10);
}
Page 3 of 7
2. state = “rest”
original_y = cylinder.transform.position.y
//this method is called before every frame is rendered
Void Update(){
dy = speed * Time.deltaTime//displacement
dalpha = rotational_speed * Time.deltaTime;
position = cylinder.transform.position
if(state == “rest” && mouse is clicked)
state = “upward”
if(state == “upward”)
position.y += dy
if(position.y≥max_hieght)
state = “downward”
if(state == “downward”)
position.y -= dy
rotate(0, 0, dalpha)//rotate around the z axis
if(position.y≤original_y)
state = “rest”
cylinder.transform.position = position
}
This is one solution. Others may work as well.
Page 4 of 7
Question 3 [35 pts]: Explain what the following code is doing. Draw a rough sketch of the scene after
this code runs.
void Start()
{
float radius = 10;
int n = 20;
float d_alpha = 360f / n;
float alpha = 0;
for (int i = 0; i < n; i++){
alpha += d_alpha;
Quaternion rotateAround = Quaternion.Euler(0, alpha, 0);
Vector3 disp = rotateAround * (Vector3.right * radius);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.localScale = new Vector3(3, 1, 1);
cube.transform.Rotate(0, alpha, 0);
cube.transform.position = disp;
}
}
Page 5 of 7
This code creates 20 cubes.
The resulting scene is 20 cubes arranged in a circle in the xz plane around the y axis resembles this rough
sketch:
Page 6 of 7
Page 7 of 7