Sign in to follow this  
kemperrr

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

Recommended Posts

kemperrr    125

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
  • Like 2

Share this post


Link to post
Share on other sites
bulatei    0
В 15.07.2017 в 08:09, kemperrr сказал:

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])
    }
})

 

вместо 'createCam': () { .... } нужно наверно 'createCam': () => { .... } либо 'createCam': function() { .... }

Share this post


Link to post
Share on other sites
kemperrr    125
12 часа назад, bulatei сказал:

вместо 'createCam': () { .... } нужно наверно 'createCam': () => { .... } либо 'createCam': function() { .... }

я писал этот пример прямо в браузере, так что да, ошибки могут быть

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  

  • Recently Browsing   0 members

    No registered users viewing this page.