Jittering crosshair with camera

M

Mew_TheCat

Guest
I have a slight problem with my crosshair jittering when i move the camera.

obj_mouse:
step:
x = mouse_x;
y = mouse_y;
obj_camera:
step:
viewx = ((obj_player_ship.x-view_wview/2)*(viewdist-1)+(mouse_x-view_wview/2))/viewdist;
viewy = ((obj_player_ship.y-view_hview/2)*(viewdist-1)+(mouse_y-view_hview/2))/viewdist;

viewx2 = viewx2-(viewx2-viewx)*0.4;
viewy2 = viewy2-(viewy2-viewy)*0.4;

view_xview = viewx2;
view_yview = viewy2;

I am fairly sure it has something to do with the player moving and the camera not being able to work with the player movement and the mouse position, but I am not sure how to fix it.
 
D

Dlastons

Guest
I have this issue as well, any help would be appreciated :)

(I edited this because I couldn't remove it and I wanted to prank Mew, as we are bestest friends in the whole wide world.)
 
J

Jordan Robinson

Guest
The jittering is most likely associated with the x and y values not being whole numbers. I would suggest doing something along the lines of


Code:
view_xview = round(viewx2);
view_yview = round(viewy2);
 
S

Snail Man

Guest
I think it has to do with the crosshair position being updated before the screen, so there's a slight lag on the crosshair position that reads as jitter. Try moving the crosshair code into the begin-step or end-step event (I can never remember which one fixes this kind of glitch)
 
M

Mew_TheCat

Guest
I think it has to do with the crosshair position being updated before the screen, so there's a slight lag on the crosshair position that reads as jitter. Try moving the crosshair code into the begin-step or end-step event (I can never remember which one fixes this kind of glitch)
I think end-step would work best.
I have tried putting it in all 3 'steps' before, and it's still happening.
 
S

SyntaxError

Guest
The formula for viewx and viewy get a coordinate from obj_player_ship. Try moving the step event for obj_player_ship to end_step. Alternatively, you could update all the coords of all objects from within one of the objects to overcome the problem all together.

EG:
In obj_camera
obj_mouse.x = mouse_x;
 
S

Snail Man

Guest
Hmm. Well I'm stumped. Have you considered just using the draw_gui event to draw it in the middle of the screen all the time, or does it need to move dynamically in 3D space?
 
S

sparksinfinite

Guest
I struggled with this problem also, I figured out a script which works on my end.
Not sure how your player moves though, so can't say if this works on your end.

obj_camera - Create Event
Code:
/// cursor sprite

window_set_cursor(cr_none);
cursor_sprite=spr_crosshair; // change it to your name
obj_camera - End Step Event
Code:
/// move view between mouse and player

var target,
    dist, dir,
    vx, vy, vx_dif, vy_dif,
    smooth;

// target the view have to follow
target=obj_player; // change it to your name

// target distance and direction to mouse
dist = point_distance (target.x, target.y, mouse_x, mouse_y) / 2;
dir  = point_direction(target.x, target.y, mouse_x, mouse_y);

// view corner
vx = target.x + lengthdir_x(dist, dir);
vy = target.y + lengthdir_y(dist, dir);
   
vx=round(vx);
vy=round(vy);

// view center 
vx -= view_wview[0] / 2;
vy -= view_hview[0] / 2;

// difference from old view pos to new pos
vx_dif = (vx - view_xview[0]);
vy_dif = (vy - view_yview[0]);


// APPLY (with smoothness)
var smooth=4;

// if difference is large enough
if  (abs(vx_dif)>0.1)
     view_xview[0]+=vx_dif/smooth;
else view_xview[0]=vx; // snap
 
if  (abs(vy_dif)>0.1)
     view_yview[0]+=vy_dif/smooth;
else view_yview[0]=vy; // snap
Like above said, the problems can be the event order (delay) or the rounding. However, to allow a smooth view and player movement, rounding should be applied after some point (sort of dead zone) imo and not every step. It's also important where the rounding is set.
 
L

leonfook29

Guest
Used to have this problem, but my solution is quite simple:
If you use custom camera movement code(which i believe you have), do the camera movement in either step begin or step, and whatever that's suppose to move alongside with your camera in step(if camera movement code is in begin) or end step. This would make sure that the camera movement code will always run first before the ui object.

Edit: okay with your example, set your camera from step to begin step.
 
Top