It is saying that this._create camera isnt a command
// If a camera isn't assigned from the Editor, create one
if (!this.camera) {
this._createCamera();
}
var force = this.force;
var app = this.app;
// Get camera directions to determine movement directions
var forward = this.camera.forward;
var right = this.camera.right;
// movement
var x = 0;
var z = 0;
Does your script have a _createCamera
function declared somewhere?
ill check, but i have had this script for a while this problem came from no where
so part of the script is waaaaay after the 'This._CreateCamera
Movement.prototype._createCamera = function () {
// If user hasn't assigned a camera, create a new one
this.camera = new pc.Entity();
this.camera.setName("First Person Camera");
this.camera.addComponent("camera");
this.entity.addChild(this.camera);
this.camera.translateLocal(0, 0.5, 0);
};
Can you post a link to your project?
Looks like your function _createCamera
starts with an underscore, however, the createCamera()
function being called inside your Movement.js update function doesn’t have an underscore. Make sure both function names are exactly the same. Also, I noticed that your account is over its disk allowance limit, I’m not sure if this causes issues when saving scripts/assets.
it hasn’t proved an issue yet but i mightve changed it earlier
@Devortel it shows that both have an underscore
the error says
this._createCamera is not a function
This if statement is outside your update()
function.
if (!this.camera) {
this._createCamera();
}
Check the curly braces and fix your update() function so that you’re not closing it too early.
whats a curly brance? is it this? {} or this ()
this is the one outside of my update function, i don’t see whats wrong
Movement.prototype._createCamera = function () {
// If user hasn't assigned a camera, create a new one
this.camera = new pc.Entity();
this.camera.setName("First Person Camera");
this.camera.addComponent("camera");
this.entity.addChild(this.camera);
this.camera.translateLocal(0, 0.5, 0);
};
Your problem is that your Movement.js update function ends on line 105, but you’re trying to call this._createCamera();
on line 110 which is outside of the update()
function.
so do i move the whole thing up a few lines?
At least move this statement inside the update() function:
if (!this.camera) {
this._createCamera();
}
You have a lot more code outside the update() function as well.
so do i move my movement into the update function as well?
That part is up to you, but I’d say yes, you probably should.
i moved the camera and im getting all sorts of errors
That code has probably been sitting there, inactive for a while. I’d say comment it out for now and see if the original _createCamera()
error is gone.