Saturday, March 1, 2025
spot_img

How to make sure strict digicam following the participant with out digicam jerkiness or delayed following? – Cocos Creator


Hello,
The digicam follows late and with jerkiness the participant

in replace() i’m merely setting the rate worth and getting it’s up to date place to set to digicam node

import { _decorator, Digital camera, Element, EventKeyboard, enter, Enter, KeyCode, math, Node, RigidBody, RigidBody2D, Vec2, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('cubeMovement')
export class cubeMovement extends Element {


    public rigidBody:RigidBody2D;

    left
    proper
    velocity
   


    @property(Digital camera)
    cam:Digital camera

    
    onLoad() {
        this.rigidBody = this.getComponent(RigidBody2D);
        this.left = false;
        this.proper = false;
        this.velocity = 20;

        enter.on(Enter.EventType.KEY_DOWN, (occasion: EventKeyboard)=>{

            if(KeyCode.ARROW_LEFT == occasion.keyCode){
                this.left = true;
            }
            else if(KeyCode.ARROW_RIGHT == occasion.keyCode){
                this.proper = true;
            }

        }, this);


        enter.on(Enter.EventType.KEY_UP, (occasion: EventKeyboard)=>{
            this.left = false;
            this.proper = false;
        }, this);



    }

    protected lateUpdate(dt: quantity): void {
        
    }

    replace(deltaTime: quantity) {


        if(this.left){
            this.rigidBody.linearVelocity = new Vec2(-this.velocity, this.rigidBody.linearVelocity.y);
        }
        else if(this.proper){
            this.rigidBody.linearVelocity = new Vec2(this.velocity, this.rigidBody.linearVelocity.y);
        }
        else{
            this.rigidBody.linearVelocity = new Vec2(0, 0);
        }

        this.cam.node.setPosition(this.node.place.x, this.node.place.y);
                
    }
}


I’ve tried following options and none of them works

  1. placing the digicam replace place in lateUpdate()
  2. tried lerp the place if I set worth 0 (as a result of I want immediate digicam following) it begin exhibiting like authentic jerkness digicam problem

Any thought the way to repair?

Thanks

You need to use Vec3.lerp to create a linear interpolation of goal place, then set it to the digicam node place.

I attempted it and it really works like clean following however I wished to have actual digicam following with out animation, setting the worth of time of lerp to 0 begin exhibiting the identical jerkiness impact, in the intervening time placing the digicam as a toddler contained in the participant node serve the aim however wish to do the identical being with out the kid of participant node & with out lerp

May you present the demo for me to examine?

Attempt transferring the next code line into the lateUpdate methodology.

this.cam.node.setPosition(this.node.place.x, this.node.place.y);

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles