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

Legacy GM Camera stops following player

V

VicoZann

Guest
As I was adding up more mechanics to my game I noticed that, for some reason, whenever my character is in his defense state script and moving, the camera stops in place, going back to following him when he stops moving or goes to another state.

///create camera


instance_create(x,y,obj_cam); // create the camera object at the player's location
cam = obj_cam;


view_hborder = view_wview/2; //set the view's horizontal border to keep the camera object centered
view_vborder = view_hview/2; // set the view's vertical border to keep the camera object centered

// Initialize Camera Variables

h_dist = 50; // set how far away horizontally the camera should be from the player
v_dist = 50; // set how far away vertically the camera should be from the player
cam.xTo = x + h_dist; // set the cam's initial xTo position
cam.yTo = y - v_dist; // set the cam's initial yTo position
peek = sprite_width + 1; // set the distance to check if a player is looking over a ledge​

This is the creation code for the camera


///Move Camera

if(input_sprint && state != PLAYER_STATE.defense)
{
h_dist = 130;
}
else
{
h_dist = 50;
}




// by default, look far in the direction the player is facing and slightly upward
cam.xTo = x + facing*h_dist;
cam.yTo = y - v_dist;


//falling camera
if(!grounded)
{
if(yspeed >= 7)
{
cam.xTo = x + facing*peek;
cam.yTo = y + v_dist*1.7;
}
}
// wallsliding camera
if(action == PLAYER_ACTION.wall_slide || action == PLAYER_ACTION.wall_run)
{
cam.xTo = x + facing*h_dist;
cam.yTo = y;
}


//move the camera

cam.x += (cam.xTo-cam.x)/cam_spd;
cam.y += (cam.yTo-cam.y)/cam_spd;​


And this the step event for the camera
I'm failling to notice what's making the camera stop working when changing to that specific state and only when moving in it.


yspeed += grav;

if(input_right)
{
xspeed = defense_speed;
}

if(input_left)
{
xspeed = -defense_speed;
}

if((!input_right && !input_left) || (input_right && input_left))
{
xspeed = 0;
}

if(xspeed = 0)
{
action = PLAYER_ACTION.defense;
}
if (xspeed !=0)
{
action = PLAYER_ACTION.defensew;
}
if (input_jump)
{
if(jump_current > 0 && grounded) //Normal jump

{
yspeed = -sqrt(2 * grav * jump_height); //This calculates the required speed to
jump_current--; //reach the desired height.
}
}

//state change

//attack
if(input_atk)
{
image_index = 0;
state = PLAYER_STATE.atk;
exit;
}

//normal
if(!input_defense || !grounded)
{
image_index = 0;
state = PLAYER_STATE.normal;
exit;
}​

Finally this is the script for the defense state. The camera object is just an empty object that moves around where it's needed, no code in there. Everything is in the create and step events of the player character
 
V

VicoZann

Guest
Noone knows what could be going wrong here? I really need help with this
 
J

JayArrington

Guest
Do you have a skype? I may be able to figure this out.
 

obscene

Member
Your code is a bit confusing so most of us look at it and go "BLAH" and move the next topic lol.

Just a tip, please include the event and object BEFORE the code because it took me a few reads to realize you had it upside down from what people normally do and that changed my thinking.

So, probably what's happening are those "exit;" lines are skipping the rest of the event including the code that moves your camera. Remember, when you say "exit;" anything after that is skipped even if it's in other code blocks, outside of the script, etc.
 
V

VicoZann

Guest
Your code is a bit confusing so most of us look at it and go "BLAH" and move the next topic lol.

Just a tip, please include the event and object BEFORE the code because it took me a few reads to realize you had it upside down from what people normally do and that changed my thinking.

So, probably what's happening are those "exit;" lines are skipping the rest of the event including the code that moves your camera. Remember, when you say "exit;" anything after that is skipped even if it's in other code blocks, outside of the script, etc.
I don't believe that the "exit"'s are the problem. They just finish a state script so the character can move on to the next one, in wich the camera works. Pretty much all my states are similar in the formating, so the defense state giving me problems is weird to say the least.

Do you have a skype? I may be able to figure this out.
I may still be able to find my old skype account, but I have no mic, though. Unless you just need some fast messaging. Did you get any idea of what could be the issue?
 
V

VicoZann

Guest
I FOUND THE PROBLEM. but I can't solve it because it makes no sense. Seens like the animation is causing the problem, for some reason.

I deleted the whole code for blocking and wrote it all again checking step by step what worked and what didn't and seens like when I use the animation that blocks and walks, the camera won't move. I have a different animation for the just standing blocking and it works with only this. I tested it out changing the animation for walking while blocking for other animations and it also works. Only the walk and block animation gives me this problem, so I ask everyone here. WTF?
 
Top