Skip to content

Commit 26d4f47

Browse files
committed
camera view
1 parent 6189d8c commit 26d4f47

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

js/gameCoins.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
green: 0x669900,
2020
};
2121
var camera_x;
22+
var camera_y;
23+
var camera_z_position;
24+
var camera_z_look;
2225
var deg2Rad = Math.PI / 180;
2326

2427
// Make a new world when the page is loaded.
@@ -70,6 +73,9 @@ function World() {
7073
function init() {
7174
// Locate where the world is to be located on the screen.
7275
camera_x=0;
76+
camera_y=700;
77+
camera_z_position = -1600;
78+
camera_z_look = -100000;
7379
element = document.getElementById("world");
7480

7581
// Initialize the renderer.
@@ -94,11 +100,10 @@ function World() {
94100
1,
95101
120000
96102
);
97-
// camera.position.set(0, 1500, -2000);
98-
// camera.lookAt(new THREE.Vector3(0, 600, -5000));
99103

100-
camera.position.set(0, 700, -1600);
101-
camera.lookAt(new THREE.Vector3(0, 650, -10000));
104+
//init camera for first time
105+
camera.position.set(0, camera_y, camera_z_position);
106+
camera.lookAt(new THREE.Vector3(0, 650, camera_z_look));
102107
window.camera = camera;
103108

104109
// Set up resizing capabilities.
@@ -124,6 +129,7 @@ function World() {
124129
scene.add(cube);
125130
});
126131

132+
//create walls
127133
var geometryLeft = new THREE.BoxGeometry(3000, 1000, 120000);
128134
const loaderLeft = new THREE.TextureLoader();
129135
loaderLeft.load("js/metal_text.jpg", (texture) => {
@@ -631,8 +637,20 @@ function Character() {
631637
break;
632638
}
633639
}
634-
camera.position.set(camera_x, 700, -1600);
635-
camera.lookAt(new THREE.Vector3(camera_x, 650, -10000));
640+
// camera.position.set(camera_x, 700, -1600);
641+
// camera.lookAt(new THREE.Vector3(camera_x, 650, -10000));
642+
643+
// if(camera_y >= 650){
644+
// camera_y -=1;
645+
// }
646+
647+
//follow character
648+
camera_z_position -= 100;
649+
camera_z_look -= 100;
650+
651+
camera.position.set(camera_x, camera_y, camera_z_position);
652+
camera.lookAt(new THREE.Vector3(camera_x, 650, camera_z_look));
653+
636654
window.camera = camera;
637655

638656
// If the character is jumping, update the height of the character.
@@ -703,6 +721,8 @@ function Character() {
703721
}
704722
}
705723
}
724+
//move person forward
725+
self.element.position.z -= 100;
706726
};
707727

708728
/**

0 commit comments

Comments
 (0)