• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Why does my camera/viewport move on it's own like it has speed?

M

MatthewL019

Guest
Alright. What I'm trying to do is, essentially, make a camera object, and have it spawn inside the player. The camera object then has a 32 pixel radius around the player in which it can move. The camera's view is set to the x and y coordinates of the camera. Now, this works as intended as you will see in the GIF below (the first couple seconds, anyway). After the first couple seconds, I move my mouse INSIDE the radius circle, and for some reason the view starts to zoom around and have a mind of its own. The exact same code (obviously with some tweaking to make it compatible for GM:S 2) did not have this error, in-fact it worked great.

GIF (first couple seconds, works fine, then after that I put my mouse in the circle and LEAVE it still, the view/background is moving NOT the mouse):
https://gyazo.com/ceabea8f19b6ac83e2782cd85ab8d52a

In my obj_controller's create event, here is where I set up the camera:
Code:
globalvar camera;
camera = camera_create_view(0,0,240,135,0,-1,-1,-1,240/2,(135/2)+0.5);
view_set_camera(0, camera);
In my obj_camera's create event:
Code:
radius = 16;
x = obj_player.x;
y = obj_player.y;
In my obj_camera's step event:
Code:
var xTo, yTo;

move_towards_point(mouse_x,mouse_y,0);
xTo = obj_player.x + lengthdir_x(min(radius,distance_to_point(mouse_x,mouse_y)), direction);
yTo = obj_player.y + lengthdir_y(min(radius,distance_to_point(mouse_x,mouse_y)), direction);

x += (xTo-x)/25;
y += (yTo-y)/25;

camera_set_view_pos(camera, xTo-(camera_get_view_width(camera)/2), yTo-(camera_get_view_height(camera)/2));
Please note, this is not the only time I have seen this 'wild' behaviour by the new camera/view system in GM:S2. I do not think it is related to this code alone, I think it is perhaps something to do with the views/cameras that maybe an option has been added that I am not aware about.
 
Top