• 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!

[SOLVED] Cursor/Camera/Object anchor offset issue

A

Arikitaru

Guest
Hello! I'm having a weird issue with a camera/shooting feature of my game.



Whenever I'm trying to shoot, the bullets are leaving from the right spot (turret), but not towards my cursor - the game thinks that the turret is about 200px higher. If I rotate my cursor around that marked spot while shooting - it's behaving properly. Note: I have a zoom feature for my camera and whenever the camera object is off, turrets behave properly.

Bullet code:

Code:
gravity = 0.11;
direction = point_direction(x,y,mouse_x,mouse_y);
direction += random_range(-4,4);
speed = 15;
image_angle = direction;
Camera code:

Code:
//Create
target = obj_rig_lg;
orig_x_size = 1280;
orig_y_size = 720;
zoom = 1;
target_zoom = zoom;

//Step
var cam_id = view_camera[0];

x += (target.x - x) * scroll_spd;
y += (target.y - y) * scroll_spd;

zoom += (target_zoom - zoom) * zoom_spd;

camera_set_view_size(cam_id, orig_x_size*zoom, orig_y_size*zoom);
var cam_width = camera_get_view_width(cam_id);
var cam_height = camera_get_view_height(cam_id);
camera_set_view_pos (cam_id, x-cam_width * 0.5, y-cam_height * 0.5);

var mouse_input = mouse_wheel_down() - mouse_wheel_up();
target_zoom += mouse_input;
target_zoom = clamp (target_zoom, 0.5, 4);
Will appreciate any advice as I'm stuck here for some time now. Checked my previous build - turrets are working properly, since then I was only working on adding some spawners, new type of projectiles and enemies. Cheers!
 
A

Arikitaru

Guest
Update: the origin point around which you have to rotate the cursor seems to be dependant on the amount of zoom. If I zoom in or out, the origin point becomes farther away from the turret itself

Update2: Solved by watching PixelatedPope's video about the cameras. Moved all code from Step to End Step and it worked just fine.
So my question is - was this due to an incorrect order of things being calculated/executed? Meaning that something in the Step event was being executed at the same time or after my camera code, causing this weird effect?
 
Last edited by a moderator:
Top