Skip to content

Commit 4e64856

Browse files
committed
Osciallate the camera around the player
1 parent fb31120 commit 4e64856

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

public/scripts.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,38 @@ for (var i = 0; i < 100; i++) {
2727
scene.add( obstacle );
2828
}
2929

30-
camera.position.z = 5;
31-
3230
var jumping = false;
3331
var jump_distance = 0.1;
3432
var acceleration = 0.0025;
3533
var acceleration_step = 0.0025;
3634

35+
var radius = 7;
36+
var thetaX = 0;
37+
var thetaY = 0;
38+
var thetaZ = 0;
39+
40+
function degrees_to_radians(degrees)
41+
{
42+
var pi = Math.PI;
43+
return degrees * (pi/180);
44+
}
45+
46+
function oscillateCamera() {
47+
thetaX += 0.1;
48+
thetaY += 0.05;
49+
thetaZ += 0.05;
50+
51+
camera.position.x = radius * Math.sin( degrees_to_radians( thetaX ) );
52+
camera.position.y = radius * Math.sin( degrees_to_radians( thetaY ) );
53+
camera.position.z = 3 + radius * Math.cos( degrees_to_radians( thetaZ ) );
54+
camera.lookAt( scene.position );
55+
}
56+
3757
var animate = function () {
3858
requestAnimationFrame( animate );
3959

60+
oscillateCamera();
61+
4062
for (var i = 0; i < obstacles.length; i++) {
4163
obstacles[i].position.x -= 0.05;
4264

0 commit comments

Comments
 (0)