Legacy GM Player shift problem while jumping

D

Drago Supremo

Guest
Hi everyone,
I've recently added a view system in my game (here's the code):
Code:
//Sets the view borders
leftBorderAxis = view_xview + view_hborder;
rightBorderAxis = view_xview + view_wview - view_hborder;

//Calculates player's relative position to the borders
difLeft = spr_player.x - leftBorderAxis; 
difRight = spr_player.x - rightBorderAxis;

//Sets the view's speed if player's direction and the touching border coincide
if ((difLeft < 0) and (spr_player.hsp < 0)) or ((difRight > 0) and (spr_player.hsp > 0)) viewHoSpeed = spr_player.hsp else viewHoSpeed = 0;

//Checks if the view is about to exit the room and moves it to the edge
if (view_xview + viewHoSpeed < 0) or (view_xview + view_wview + viewHoSpeed > room_width)
{
  while !(view_xview + viewHoSpeed < 0) and !(view_xview + view_wview + viewHoSpeed > room_width) view_xview += sign(viewHoSpeed)
  viewHoSpeed = 0;
}

//Moves the view
view_xview += viewHoSpeed;

//Sets the view borders
topBorderAxis = view_yview + view_vborder;
bottomBorderAxis = view_yview + view_hview - view_vborder;

//Calculates player's relative position to the borders
difTop = spr_player.y - topBorderAxis; 
difBottom = spr_player.y + view_yview - bottomBorderAxis;

//Sets the view's speed if player's direction and the touching border coincide
if ((difTop < 0) and (spr_player.vsp < 0)) or ((difBottom > 0) and (spr_player.vsp > 0)) viewVoSpeed = spr_player.vsp else viewVoSpeed = 0;

//Checks if the view is about to exit the room and moves it to the edge
if (view_yview + viewVoSpeed < 0) or (view_yview + view_hview + viewVoSpeed > room_height)
{
  while !(view_yview + viewVoSpeed < 0) and !(view_yview + view_hview + viewVoSpeed > room_height) view_yview += sign(viewVoSpeed)
  viewVoSpeed = 0;
}

//Moves the view
view_yview += viewVoSpeed;
The horizontal view works fine, but using the vertical view i get a strange effect when the player is jumping and is about to reach its maximum jump height. In fact it's like it shift for some pixels higher.
Here's the code for variable jump and gravity:

Jump:
Code:
if (vsp < 0) and !(key_jump) vsp = max(vsp, 0);
Gravity:
Code:
if (vsp <= 10) 
  {
    vsp += grav;
  }
Things i've already tried:
- I know that Game Maker has some problems drawing objects at non-integer coordinates, so i tried setting the gravity to 1 instead of 0.4 (even if it was much better);
- I tried setting room's speed to 60 fps to make the game smoother, but it didn't work.

I hope i explained myself sufficiently well and thank you in advance for your help.
 

TheouAegis

Member
if vsp < 0, then max(vsp,0) is always 0.

Other than that, I didn't catch any typos in your code that would make one work and not the other.
 
D

Drago Supremo

Guest
if vsp < 0, then max(vsp,0) is always 0.

Other than that, I didn't catch any typos in your code that would make one work and not the other.
It's for the variable jump. In effect the real jump code is more this:
Code:
  if (place_meeting(x, y + 1, obj_all_solids))      
  {
    vsp = key_jump * -jumpSpeed;
  }
I'm sorry i forgot to add it, actually the other piece of code just sets the vertical speed to 0 when the player release the jump key to make the jump variable.
 

CedSharp

Member
Then I don't think the problem comes from the pieces of code you provided.
You might want to add some
Code:
show_debug_message( "Variable test: "+string( test ) );
to debug the actual values that you're using.

I can't seem to find a problem with your actual code without seeing the rest of your project :/

Regards,
Cedsharp
 
D

Drago Supremo

Guest
Then I don't think the problem comes from the pieces of code you provided.
You might want to add some
Code:
show_debug_message( "Variable test: "+string( test ) );
to debug the actual values that you're using.

I can't seem to find a problem with your actual code without seeing the rest of your project :/

Regards,
Cedsharp
I uploaded my project so if you want you can take a look to it. It's just a training pool to test everything i need.
https://drive.google.com/folderview?id=0BywFroUti72kdm9vckpKNDZyUEE&usp=sharing

Another thing i've noticed is that when the player lands on the ground it seems to be one pixel above or below it.
I don't know if this mean something, but to be sure i told you about.
 

CedSharp

Member
I'll take a quick look, but my condition is that I won't tell you the answer, I'll just tell you what's wrong :)
Hopefully that should set you on the right track ~
 

CedSharp

Member
Ah sorry, google drive doesn't download the project correctly ( it keeps adding .html at the end of all files and re-orders them outside the folders 0-0 )
Can you instead, in gamemaker, go in File > Export Project, and then link me to this new "file.gmz" please?
shouldbe more reliable.

this is what google drive makes me download:
 
D

Drago Supremo

Guest
Ah sorry, google drive doesn't download the project correctly ( it keeps adding .html at the end of all files and re-orders them outside the folders 0-0 )
Can you instead, in gamemaker, go in File > Export Project, and then link me to this new "file.gmz" please?
shouldbe more reliable.

this is what google drive makes me download:
Excellent it's exactly not knowing what's wrong that drives me mad :D.
Here's a new link that should work: https://drive.google.com/folderview?id=0BywFroUti72kdm9vckpKNDZyUEE&usp=sharing
Thank you very much :)
 

CedSharp

Member
I seem to realize that the problem you're having is not related to your movement script at all.
IT is related to your sprites.
Basically, they don't have the same size.
The idle animation is a good example. Try just running left and right without even jumping.
Sometimes you'll be perfectly on the groud, somethimes a couple pixels in the air... and you can even see that the
idle animation makes you float only one frame on 2!

So definitly check your sprites, make sure they are well aligned, and make sure you set the origin correctly.

Regards ~
Cedsharp
 
D

Drago Supremo

Guest
I seem to realize that the problem you're having is not related to your movement script at all.
IT is related to your sprites.
Basically, they don't have the same size.
The idle animation is a good example. Try just running left and right without even jumping.
Sometimes you'll be perfectly on the groud, somethimes a couple pixels in the air... and you can even see that the
idle animation makes you float only one frame on 2!

So definitly check your sprites, make sure they are well aligned, and make sure you set the origin correctly.

Regards ~
Cedsharp
Sorry for the late reply but i could try to fix these problems only today.
I took a look at my sprites but except for the run animation (which had many sprites not aligned) i can't find anything wrong in the others and the origin of all sprites is in their bottom edge.
Modifying my animation also caused a strange bug: the black wall objects seem to be not aligned anymore, but i don't understand how modifying a totally different sprite can cause this issue...
I uploaded my project again so that you can see the changes.

P.S: i see that the black walls' bug happened after doing this: re-load a new spr_playerResource file and cut two sprites from it to replace them to two in the run animation. I still don't understant how can that be connected...
 
Top