Assistance in creating camera functionality

I’m trying to create a camera similar to that of an indie title called “The Exiled”. In this game the camera follows the player, but is allowed to pivot based on the users mouse location. You can see an example of this game here: https://youtu.be/Pe4PJKMx4Iw?t=40

I’m not 100% sure on if this game uses an orthographic or perspective camera, but as of right now I’m working with perspective.

I’ve already worked out the camera code to follow the player, and it looks like this:

var PlayerCamera = pc.createScript('playerCamera');

PlayerCamera.attributes.add('playerEntity', { type: 'entity' });

// initialize code called once per entity
PlayerCamera.prototype.initialize = function() {
    if(!this.playerEntity) throw 'PlayerCamera does not have a specified Player Entity.';    

    this.distanceOriginal = new pc.Vec3(); 
    this.distanceOriginal.add(this.entity.getPosition()); 
    this.distanceOriginal.sub(this.playerEntity.getPosition());
    this.lastChange = new pc.Vec3(); 
    
    this.empty = new pc.Vec3(); 
    
    console.log("Distance original:", this.distanceOriginal);
    
    var self = this; 
    this.app.on('player:moved', function(playerPosition) {
        var distance = new pc.Vec3(); 
        var position = self.entity.getPosition(); 

        distance.add(position);
        distance.sub(playerPosition); 
        
        var change = new pc.Vec3(); 
        change.add(self.distanceOriginal);
        change.sub(distance);

        var newPosition = new pc.Vec3(); 
        newPosition.copy(self.entity.getPosition());
        newPosition.add(change);
        
        if(change.equals(self.empty)) return;
        self.entity.setLocalPosition(newPosition); 
    });
    
};

I just haven’t figured out pivoting with the mouse at all, any assistance would be greatly appreciated, or even just implementation details.

The camera rules are as follows…

1: Camera has an anchor point (The Player)
2: Camera can only travel X distance from anchor.
3: GameObjects should not increase/decrease in size as camera moves.

Hello,
Greetings

I’d Glad to assist you.
PM Sent, Please Check.

Very Best Regards
Carter W

Thanks for your response Carter, unfortunately I posted this is the wrong section.

Without playing the game, it looks like the camera centers on the half way point between the player and the mouse pointer. Looks like an orthographic camera too.

1 Like