Skip to content
Permalink
Browse files

Osciallate the camera around the player

  • Loading branch information
MattyRad committed Feb 13, 2020
1 parent fb31120 commit 4e64856e37cc289cac529319a01ca77753367b18
Showing with 24 additions and 2 deletions.
  1. +24 −2 public/scripts.js
@@ -27,16 +27,38 @@ for (var i = 0; i < 100; i++) {
scene.add( obstacle );
}

camera.position.z = 5;

var jumping = false;
var jump_distance = 0.1;
var acceleration = 0.0025;
var acceleration_step = 0.0025;

var radius = 7;
var thetaX = 0;
var thetaY = 0;
var thetaZ = 0;

function degrees_to_radians(degrees)
{
var pi = Math.PI;
return degrees * (pi/180);
}

function oscillateCamera() {
thetaX += 0.1;
thetaY += 0.05;
thetaZ += 0.05;

camera.position.x = radius * Math.sin( degrees_to_radians( thetaX ) );
camera.position.y = radius * Math.sin( degrees_to_radians( thetaY ) );
camera.position.z = 3 + radius * Math.cos( degrees_to_radians( thetaZ ) );
camera.lookAt( scene.position );
}

var animate = function () {
requestAnimationFrame( animate );

oscillateCamera();

for (var i = 0; i < obstacles.length; i++) {
obstacles[i].position.x -= 0.05;

0 comments on commit 4e64856

Please sign in to comment.
You can’t perform that action at this time.