- forward = vectoangles(normalize(vec_to_min(position_b, position_a) - vec_to_max(position_b, position_a)));
- backward = vectoangles(normalize(vec_to_max(position_b, position_a) - vec_to_min(position_b, position_a)));
-
- if(input_movevalues_y < 0) // left
- view.angles_y = backward_y;
- if(input_movevalues_y > 0) // favour right
- view.angles_y = forward_y;
-
- setproperty(VF_CL_VIEWANGLES, view.angles);
+ if(spectatee_status)
+ return; // if spectating, don't replace angles or inputs!
+
+ if (have_sidescroll) {
+ vector view_angle = view.angles;
+ if (!(view.viewloc.spawnflags & VIEWLOC_FREEAIM)) {
+ vector avatar_facing_dir;
+ // get the player's forward-facing direction, based on positions a and b
+ if (0 == input_movevalues.y) {
+ avatar_facing_dir = view_angle; // default to the previous values
+ } else if (0 > input_movevalues.y) { // left is forward
+ avatar_facing_dir = vectoangles(normalize(vec_to_max(position_b, position_a) - vec_to_min(position_b, position_a)));
+ } else { // right is forward
+ avatar_facing_dir = vectoangles(normalize(vec_to_min(position_b, position_a) - vec_to_max(position_b, position_a)));
+ }
+ view_angle.y = avatar_facing_dir.y; // snap avatar to look on along the correct axis
+
+ // if (0 == input_movevalues.x) look straight ahead
+ if (!(view.viewloc.spawnflags & VIEWLOC_FREEMOVE)) {
+ if (0 > input_movevalues.x) { // look up
+ view_angle.x = 50;
+ } else if (0 < input_movevalues.x) { // look down
+ view_angle.x = -50;
+ }
+ }
+ } else {
+ vector mpos = CursorToWorldCoord(viewloc_mousepos);
+ mpos.x = view.origin.x; // replace the cursor's x position with the player's
+ view_angle = aim_vec(view.origin + view.view_ofs, mpos); // get new angles
+ }
+ view.angles_y = view_angle.y;
+ setproperty(VF_CL_VIEWANGLES, view_angle);
+ }