• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED]smooth camera and offset

Niels

Member
Hi everyone,

I have a problem with my camera/view.
In my game the camera follows the player, but with a offset.
This way roughly 2/3th of the view is to the front of the player
example:
voorbeeld camera.png

My camera code is the following:
//view[0] follows player
view_xview[0] = obj_player.x - view_wview[0] /2 + (100 * obj_player.image_xscale);
view_yview[0] = obj_player.y - view_hview[0] /1.8;​

This works fine except that when I change direction the camera instantly snaps to it's new position.

This gives a disorientating effect since it creates the illusion that the player himself warps from the right 3th to the left 3th of the screen.

I would like a smooth camera movement to the new position when changing direction, but I'm kinda lost in how to do this. (without using views in the room editor);

anyone care to give me some pointers?
 

obscene

Member
You want to create a camera object that the view follows, and that you can code the camera object to move freely around via code.

// Example
var xx=obj_player.x+image_xscale*100;
var yy=obj_player.y;
x=lerp(x,xx,.01);
y=lerp(x,xx,.01);

Or use move_towards_point or whatever looks right for your game.
 
I think the thing that would most directly accomplish what you are trying to do is to have two variables for the offset.

One is the actual offset, the other is what it is trying to be.

So then you could make the actual offset just lerp toward the newly desired offset

true_offset = lerp( true_offset, desired_offset, 0.05 );
 

Niels

Member
thanks a lot, obscenes code works great, (reminder to self: use Lerp more!)

1 more question:

Is there a way to make the camera NOT stop at roomborders?
view_hborder tells me this:
NOTE: if you are not setting the x and y position of the view manually, the view never leaves the boundaries of the room. This means that when the view reaches the edge of a room, the horizontal and vertical borders are ignored and the instance will move freely within the view.

but I'm not sure what they mean by it
 

kamiyasi

Member
thanks a lot, obscenes code works great, (reminder to self: use Lerp more!)

1 more question:

Is there a way to make the camera NOT stop at roomborders?
view_hborder tells me this:
NOTE: if you are not setting the x and y position of the view manually, the view never leaves the boundaries of the room. This means that when the view reaches the edge of a room, the horizontal and vertical borders are ignored and the instance will move freely within the view.

but I'm not sure what they mean by it
Set the x and y values of the view manually if you don't want the view to stop at the boundaries of the room. If you're using view_xview[0] = and view_yview[0] = already, then it shouldn't be stopping at the room boundaries.
 

Niels

Member
Set the x and y values of the view manually if you don't want the view to stop at the boundaries of the room. If you're using view_xview[0] = and view_yview[0] = already, then it shouldn't be stopping at the room boundaries.
thx alot,
 
Top