[SOLVED] Camera from A to B

Hello, seems i have lost my touch after 1yr far from coding, i want move the camera from A to B so i made this 3 functions, but seems i missed something, since camera ignore me :smiley:

      update: function (dt) {
            app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
            if (this.state==='move') {
                /*var position = this.entity.getPosition();
                position.lerp(this.entity.getPosition(),this.targetPosition,0.1);
                this.entity.setPosition(position);
                */temp.sub2(this.targetPosition, this.entity.getPosition());
                distance = temp.length();
                if (distance < this.walkAnimCutoff) {
                    this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
                    this.state="idle";
                }
                temp.normalize().scale(this.moveSpeed);
                this.entity.rigidbody.linearVelocity = temp;
                temp.sub2(this.entity.getPosition(), this.targetPosition);
                this.entity.rigidbody.syncEntityToBody();
            }
        },
        onMouseDown: function (e) {
            if (e.button === pc.MOUSEBUTTON_LEFT) {
                this.moveTo(0.68,3.657,-1);
            }
        },
        moveTo: function (position) {
            this.moveTimer = 0.4;
            this.startPosition.copy(this.entity.getPosition());
            this.targetPosition.copy(position);
            this.state='move';
        },

This looks like the legacy syntax. You might wanna re-check the docs to revise some stuff on syntax.

Not sure why you are this.entity.rigidbody.syncEntityToBody(); if you are already moving it via changing the local velocity.

true that line is unnecessary @yaustar . Tnx i will revise the syntax @DevPlex01

@ayrin

Forgot to mention, as you have been away for a year, PlayCanvas has stopped supporting the older script system so you can no longer fork old projects :frowning:

I know this will be a pain with your game as it’s quite large.

:frowning: yes quite a pain, there is a list of changed instructions from legacy to 2.0 scripts? so i can check and adapt the code and rebuild the whole project?

Some of the script syntax is different but the API is mostly the same. You may need @will or @codebon to fork your project for you with new scripting system enabled?

yea, that should be helpful. I think i will loose my mind by doing the conversion :smiley:

Oh, you will still need to do conversion unfortunately :sweat:

It’s just that the project needs the setting enabled which isn’t accessible to a user.

yes guessed so much @yaustar :smiley: so the conversion will cause me some headache :stuck_out_tongue: as punition the staff will have to provide me painkillers for a week :smiley: LOL

modified the code, i still miss something to make the camera move forward the destination

pc.script.create('cameraCinematic', function (app) {
    // Creates a new CameraCinematic instance
    var temp = new pc.Vec3();
    var CameraCinematic = function (entity) {
        this.entity = entity;
        this.startPosition = new pc.Vec3();
        this.targetPosition = new pc.Vec3();
        this.state='idle';
        this.entity.rigidbody.enabled=true;
    };

    CameraCinematic.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
            this.entity.position=this.entity.getPosition();
            app.mouse.on("mousedown", this.onMouseDown, this);
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
            app.mouse.on("mousedown", this.onMouseDown, this);
            if (this.state==='move') {
                /*var position = this.entity.getPosition();
                position.lerp(this.entity.getPosition(),this.targetPosition,0.1);
                this.entity.setPosition(position);
                */temp.sub2(this.targetPosition, this.entity.getPosition());
                distance = temp.length();
                if (distance < 0.8) {
                    this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
                    this.state="idle";
                }
                temp.normalize().scale(0.15);
                this.entity.rigidbody.linearVelocity = temp;
                temp.sub2(this.entity.getPosition(), this.targetPosition);
            }
        },
        onMouseDown: function (e) {
            if (e.button === pc.MOUSEBUTTON_LEFT) {
                var dest=new pc.Vec3(0.68,3.657,-1);
                this.moveTo(dest);
            }
        },
        moveTo: function (position) {
            this.startPosition.copy(this.entity.getPosition());
            this.targetPosition.copy(position);
            this.state='move';
        },
    };

    return CameraCinematic;
});

Btw, sorry for the work you’re gonna have to go through. If you have any questions @yaustar and I are free to answer.

thanks a lot @DevPlex01 i knew that soon or later i would have to go through that, i was just lazy coz of the size of the project. Well i will summon all my patience :stuck_out_tongue:

1 Like

solved this way

update: function (dt) {
            app.mouse.on("mousedown", this.onMouseDown, this);
            if (this.state==='move') {
                var dest=new pc.Vec3(0.68,2.657,-0.5);
                this.moveTo(dest);
            }
        },
        onMouseDown: function (e) {
            if (e.button === pc.MOUSEBUTTON_LEFT && this.state=="idle") {
                var dest=new pc.Vec3(0.68,2.657,-1);
                this.moveTo(dest);
            } 
        },
        moveTo: function (position) {
            this.startPosition.copy(this.entity.getPosition());
            this.targetPosition.copy(position);
            this.state='move';
            var position = new pc.Vec3();
            position.lerp(this.targetPosition,this.startPosition,0.99);
            this.entity.setPosition(position);
            this.entity.rigidbody.syncEntityToBody();
        },
1 Like

Glad you found your answer.

1 Like

Thanks, it takes a bit to remove dust from knowledge :stuck_out_tongue:

1 Like

01111001 01110101 01110000 01100001 01100111 01110010 01100101 01100101 01100100

Above this sentence is a sentence in binary lol.

Never call syncEntityToBody - it’s an internal function. Use teleport to set the position (and rotation) of an rigidbody-enabled entity explicitly.

1 Like

@DevPlex01 thanks for the help to remove dust, i will translate it tomorrow getting my sweet time (i have used binary just for math so i need to investigate about letters lol)
@will ok thanks I will change it

1 Like