Sign in to follow this  
kemperrr

Smooth camera (very simple option)

Recommended Posts

kemperrr    137

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;

 

Using

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])
    }
})
  • Like 1

Share this post


Link to post
Share on other sites

I've got error "TypeError: Cannot read property 'new' of undefined
            const cam = mp.cameras.new('default', new mp.Vector3(0, 0, 75), new mp.Vector3(), 90.0);"

How to fix this?

----------------

My bad, this should be used on client side!

Edited by TroublesMader
Adding solution

Share this post


Link to post
Share on other sites
kemperrr    137
5 часов назад, TroublesMader сказал:

Ошибку выдает "TypeError: Cannot read property 'new' of undefined
            const cam = mp.cameras.new('default', new mp.Vector3(0, 0, 75), new mp.Vector3(), 90.0);"

Как это пофиксить?

ты точно на клиенте используешь?

  • Like 1

Share this post


Link to post
Share on other sites

kemperrr, my bad. But now I've put this to client packages, everything is set up nice, but no effect in the game. What this resource should do at all?

Edited by TroublesMader
changing language - that's english topic

Share this post


Link to post
Share on other sites
kemperrr    137

try this

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);
		mp.game.cam.renderScriptCams(true, false, 3000, true, false);
        interpolateCam(cam, [new mp.Vector3(0, 0, 75), new mp.Vector3(1337, 1448, 228), 1])
    }
})

 

Share this post


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

try this

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);
		mp.game.cam.renderScriptCams(true, false, 3000, true, false);
        interpolateCam(cam, [new mp.Vector3(0, 0, 75), new mp.Vector3(1337, 1448, 228), 1])
    }
})

 

Yeah, I tried exactly this, but one string syntax seems wrong, so next string I made like this 

'createCam': () => {

 

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   1 member