Ошибка get_move_style(): Wrong camera object

26 февраля 2019 11:00
По примеру урока firstperson написал собственное приложение, но открыв консоль в браузере выдаёт ошибку B4W ERROR: get_move_style(): Wrong camera object
Помогите разобраться что я не так написал

<!DOCTYPE html>
<html>

<head>

<title>Nature Reserve</title>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="Petigor's Tale action role-playing game." />
<script type="text/javascript" src="b4w.min.js"></script>
<script type="text/javascript" src="Nature Reserve.js"></script>
body {
margin: 0;
padding: 0;
overflow: hidden;
}

div#canvas3d {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<div id="canvas3d"></div>
</body>
</html>

"use strict"

// register the application module
b4w.register("Nature Reserve_main", function(exports, require) {

// import modules used by the app
var m_app = require("app");
var m_cons = require("constraints");
var m_ctl = require("controls");
var m_data = require("data");
var m_main = require("main");
var m_mouse = require("mouse");
var m_phy = require("physics");
var m_scs = require("scenes");
var m_trans = require("transform");
var m_cam = require("camera");
var m_vec3 = require("vec3");

var _vec3_tmp = new Float32Array(3);

exports.init = function() {
m_app.init({
canvas_container_id: "canvas3d",
callback: init_cb,
alpha: false
});
}

function init_cb(canvas_elem, success) {

if (!success) {
console.log("b4w init failure");
return;
}

m_app.enable_controls(canvas_elem);

window.addEventListener("resize", resize);

load();
}

function load() {
m_data.load("first-person.json", load_cb);
}

function load_cb(data_id) {
// make camera follow the character
var camobj = m_scs.get_active_camera();
var character = m_scs.get_first_character();
var offset = new Float32Array([0,0,-5]);
var dist = m_vec3.length(offset);

function rotation_cb(rot_x, rot_y) {
m_phy.character_rotation_inc(character, rot_x, 0);
if (rot_y) {
m_cam.eye_rotate(camobj, 0, rot_y);

m_cam.get_camera_angles(camobj, _vec3_tmp);
offset[2] = -dist * Math.cos(_vec3_tmp[1]);
offset[1] = -dist * Math.sin(_vec3_tmp[1]);

m_cons.remove(camobj)
m_cons.append_semi_stiff_cam(camobj, character, offset);
}
}

// enable rotation with mouse
var canvas_elem = m_main.get_canvas_elem();
canvas_elem.addEventListener("mouseup", function(e) {
m_mouse.request_pointerlock(canvas_elem, null, null, null, null, rotation_cb);
}, false);

m_cons.append_semi_stiff_cam(camobj, character, offset);

setup_movement()
}

function resize() {
m_app.resize_to_container();
}

function setup_movement() {

var key_a = m_ctl.create_keyboard_sensor(m_ctl.KEY_A);
var key_s = m_ctl.create_keyboard_sensor(m_ctl.KEY_S);
var key_d = m_ctl.create_keyboard_sensor(m_ctl.KEY_D);
var key_w = m_ctl.create_keyboard_sensor(m_ctl.KEY_W);

var move_state = {
left_right: 0,
forw_back: 0
}

var move_array = [key_w, key_s, key_a, key_d, key_shift];
var character = m_scs.get_first_character();

var move_cb = function(obj, id, pulse) {
if (pulse == 1) {
switch (id) {
case "FORWARD":
move_state.forw_back = 1;
break;
case "BACKWARD":
move_state.forw_back = -1;
break;
case "LEFT":
move_state.left_right = 1;
break;
case "RIGHT":
move_state.left_right = -1;
break;
}
} else {
switch (id) {
case "FORWARD":
case "BACKWARD":
move_state.forw_back = 0;
break;
case "LEFT":
case "RIGHT":
move_state.left_right = 0;
break;
}
}

m_phy.set_character_move_dir(obj, move_state.forw_back,
move_state.left_right);
};

m_ctl.create_sensor_manifold(character, "FORWARD", m_ctl.CT_TRIGGER,
move_array, function(s) {return s[0]}, move_cb);
m_ctl.create_sensor_manifold(character, "BACKWARD", m_ctl.CT_TRIGGER,
move_array, function(s) {return s[1]}, move_cb);
m_ctl.create_sensor_manifold(character, "LEFT", m_ctl.CT_TRIGGER,
move_array, function(s) {return s[2]}, move_cb);
m_ctl.create_sensor_manifold(character, "RIGHT", m_ctl.CT_TRIGGER,
move_array, function(s) {return s[3]}, move_cb);


}

});

b4w.require("Nature Reserve_main").init();
 
Пожалуйста, зарегистрируйтесь или войдите под своей учетной записью , чтобы оставлять сообщения.