Is there anything wrong with this code?

var CameraMovement = pc.createScript(‘cameraMovement’);

CameraMovement.attributes.add(‘mouseSpeed’, { type: ‘number’, default: 1.4, description: ‘Mouse Sensitivity’ });

// Called once after all resources are loaded and before the first update
CameraMovement.prototype.initialize = function () {
this.eulers = new pc.Vec3();
this.touchCoords = new pc.Vec2();

var app = this.app;
app.mouse.on("mousemove", this.onMouseMove, this);

app.mouse.on("mousedown", function () {
    app.mouse.enablePointerLock();
}, this);

this.rayEnd = app.root.findByName('RaycastEndPoint');

};

CameraMovement.prototype.postUpdate = function (dt) {
var originEntity = this.entity.parent;

var targetY = this.eulers.x + 180;
var targetX = this.eulers.y;

var targetAng = new pc.Vec3(-targetX, targetY, 0);

originEntity.setEulerAngles(targetAng);
               
this.entity.setPosition(this.getWorldPoint());

this.entity.lookAt(originEntity.getPosition());

};

CameraMovement.prototype.onMouseMove = function (e) {
if (pc.Mouse.isPointerLocked()) {
this.eulers.x -= ((this.mouseSpeed * e.dx) / 60) % 360;
this.eulers.y += ((this.mouseSpeed * e.dy) / 60) % 360;

    if (this.eulers.x < 0) this.eulers.x += 360;
    if (this.eulers.y < 0) this.eulers.y += 360;
}

};

CameraMovement.prototype.getWorldPoint = function () {
var from = this.entity.parent.getPosition();
var to = this.rayEnd.getPosition();

var hitPoint = to;

var app = this.app;
var hit = app.systems.rigidbody.raycastFirst(from, to);

return hit ? hit.point : to;

};

It is hard to tell without error messages. What do you see in your console?

alot

like alot of errers

ill give you the link ok

https://playcanvas.com/editor/scene/1077508

can you take a look?

i see alot can you take alook on https://playcanvas.com/editor/scene/1077508

ill try my backup code

ok

There is no objects with a “RaycastEndPoint” name in the scene. Your this.rayEnd is null.
You could use debugger for such errors.

is there anyway you can code?