Camera Control Problem

T

TonyZh

Guest
I have problems with getting my Camera Control working. I think my movement control code interferes with my Camera Control. :)

My movement uses W, S, D and A to move around and shift to walk faster.
Code:
if(keyboard_check(ord("D")) && place_free(x + collisionSpeed, y)) {
   x +=walkSpeed;
   image_speed = walkSpeed/3 ;
   sprite_index= sprSaraWalkRight;
}

if(keyboard_check(ord("A")) && place_free(x - collisionSpeed, y)) {
   x -=walkSpeed;
   image_speed = walkSpeed/3 ;
   sprite_index= sprSaraWalkLeft;
}

if(keyboard_check(ord("S")) && place_free(x, y + collisionSpeed)) {
   y +=walkSpeed;
   image_speed = walkSpeed/3 ;
   sprite_index= sprSaraWalkDown;
}

if(keyboard_check(ord("W")) && place_free(x, y - collisionSpeed)) {
   y -=walkSpeed;
   image_speed = walkSpeed/3 ;
   sprite_index= sprSaraWalkUp;
}

if(keyboard_check(vk_nokey)) {
   image_speed= 0;
   image_index= 0;
   walkSpeed= 3.5;
}

if(keyboard_check(vk_shift)) {
   walkSpeed= 5;
}
My Camera can move if the player presses the C button and uses the W, S, D and A button to move the Camera around. The Camera works fine if I don't move it around.
Code:
moveCam = keyboard_check(ord("C"));

if(moveCam){
   x += (keyboard_check(ord("D")) - keyboard_check(ord("A")))*6;
   y += (keyboard_check(ord("S")) - keyboard_check(ord("W")))*6;
} else {
   x = clamp(x, following.x-h_border, following.x+h_border);
   y = clamp(y, following.y-v_border, following.y+v_border);
}
and
Code:
following = objSara;
h_border = 60;
v_border = 30;
Thank you for helping me out!
 
Last edited by a moderator:

icuurd12b42

TMC Founder
GMC Elder
why are you moving the camera independently but with the same keys as the player?

anyway, seems to me a poor design, but I guess I have no idea. Would you not want to not move the player when moving the camera then? seems the player movement code should look at that moveCam variable as well
 
T

TonyZh

Guest
why are you moving the camera independently but with the same keys as the player?

anyway, seems to me a poor design, but I guess I have no idea. Would you not want to not move the player when moving the camera then? seems the player movement code should look at that moveCam variable as well
Maybe I can move the Camera with vk_up, vk_down, vk_left, vk_right. But I don't want the player to move when moving the camera.
 
Last edited by a moderator:
T

TonyZh

Guest
Thank you for helping. I found a solution

Code:
if(moveCam){
   x += (keyboard_check(vk_right) - keyboard_check(vk_left))*6;
   y += (keyboard_check(vk_down) - keyboard_check(vk_up))*6;
This way it doesn't interfere with my Movement controls. But I would have preferred to do it with the same keys. I wouldn't know how I would stop the player movement if I press C and that I will only be able to move the camera.
 
Last edited by a moderator:

icuurd12b42

TMC Founder
GMC Elder
make moveCame global.moveCam and add the same sort of if in the player

if(!global.moveCam && keyboard_check(ord("A")) && place_free....
 
T

TonyZh

Guest
I will get this error if I try to add it.
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object objSara:

global variable name 'moveCam' index (100019) not set before reading it.
at gml_Object_objSara_Step_0 (line 3) - if(!global.moveCam && keyboard_check(ord("D")) && place_free(x + collisionSpeed, y)) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_objSara_Step_0 (line 3)
 
Top