Sign in to follow this  
Followers 0
kemperrr

Плавная камера ( очень простой вариант )

1 post in this topic

Posted (edited)

ONLY 0.2

let interpolatecam = null;

function lerp (vector1, vector2, deltaTime) {
	
	return new mp.Vector3(
		vector1.x + (vector2.x - vector1.x) * deltaTime, 
		vector1.y + (vector2.y - vector1.y) * deltaTime, 
		vector1.z + (vector2.z - vector1.z) * deltaTime
	);
	
}

function init() {

    mp.events.add({
        'render': () => {
            if(interpolatecam) {
                interpolatecam.currentPosition = lerp(interpolatecam.positions[0], interpolatecam.positions[1], interpolatecam.progress);
                interpolatecam.progress = interpolatecam.progress + interpolatecam.speed / 1000;
                interpolatecam.cam.setCoord(interpolatecam.currentPosition.x, interpolatecam.currentPosition.y, interpolatecam.currentPosition.z);
                if(interpolatecam.progress >= 1) {
                    interpolatecam = null;
                }
            }
        }
    });
}

function interpolateCam (cam, positions, speed) {

    return interpolatecam = {
        cam,
        positions,
        speed,
        progress: 0,
        currentPosition: null
    };
}

exports.interpolateCam = interpolateCam;
exports.init = init;

 

Использование

const {init, interpolateCam} = require('./interpolateCam');

init();

mp.events.add({
    'createCam': () {
        const cam = mp.cameras.new('default', new mp.Vector3(0, 0, 75), new mp.Vector3(), 90.0);
        cam.setActive(true);
        interpolateCam(cam, [new mp.Vector3(0, 0, 75), new mp.Vector3(1337, 1448, 228), 1])
    }
})

 

Edited by kemperrr
1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.