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

Odd Gravity[solved]

W

Wild_West

Guest
Why is my gravity setting in my practice file so much less than in my real file? The settings are both exactly the same but the player falls too slow in the practice one and can't seem to jump as high, which makes no sense since the gravity seems to be less.

Gravity code for real and practice game files

if not( place_free(x,y+1) ){ gravity = 0; }
else
{
gravity += 0.1;
gravity_direction = 270;
}

Jump code for real and practice game files

if(place_meeting(x, y+1, parent_wall_object))) and (jump){ vspeed = -jump_height; }


platform collision for real and practice game files

move_contact_solid(direction,10);
vspeed = 0;


EDIT : I copy/pasted my code from my player object in the real game file to my practice file and that fixed it, so I tried redoing what I had to see if I could recreate the problem but it didn't work, so now I have a fixed gravity that I can't break to test the differences. What is going on here?
 
Last edited by a moderator:

Bingdom

Googledom
Maybe one of them has
gravity = 0.1
And the other has
gravity += 0.1

Gravity affects the variable vspeed.
Just increasing the gravity 0.1 per step will affect the vspeed even more.

What do you mean by practice file and real file?
Test project and real project?
 
Last edited:
W

Wild_West

Guest
Maybe one of them has
gravity = 0.1
And the other has
gravity += 0.1

Gravity affects the variable vspeed.
Just increasing the gravity 0.1 per step will affect the vspeed even more.

What do you mean by practice file and real file?
Test project and real project?
Yeah that's all it is, because my real file has gotten bigger over the time I'm working on it and takes ages to load so it's just easier to test new things in a practice file.
But I already checked the += thing while I was comparing the 2 files.
 
W

Wild_West

Guest
Okay I fixed the ability to jump off the elevators while they move down by just increasing the gravity of the player so he's always in contact with it and can actually touch ground to jump off of, but now the collision with the upward moving platforms is compromised because the gravity increase doesn't discriminate between which platform I'm on, up moving or down moving.
So I tried assigning the instances I'd be on at any time to a variable but that didn't work, and I can't use the collision event because this fix only works in the step event.
Any idea how I can complete this so my gravity is still 0 on an upward moving elevator?

Oh here's the new code :

Code:
//set the elevator's vspeed for up or down scrolling in the elevator's creation code
if( place_meeting(x,y+1,elevator_platform) )
{

  carrier = instance_nearest(x,y+1,elevator_platform); 

  if(carrier.vspeed < 0)
  //If the platform is moving up make sure your gravity and vspeed don't push against it.
  { gravity = 0;  vspeed = carrier.vspeed; }
 
  if(carrier.vspeed > 0)
  {
    //Increase gravity on the down moving platform so you don't keep losing your collision with it as gravity       adjusts at a 0.1 rate.
    gravity += 0.5; vspeed = carrier.vspeed;
  
    //Cancel the gravity increase so you can jump off.
    if(jump){ gravity = 0;  vspeed = -jump_height; }
  }
}
 

TheouAegis

Member
Is your room_speed the same in both projects, by the way? If gravity is increased every step that there is nothing under the player, then after 1 second gravity is room_speed/10, so the slower the room_speed, the lower the gravity and the higher the player will jump.

carrier = instance_nearest(x,y+1,elevator_platform);
You need instance_place(), not instance_nearest(). You could have an elevator anywhere in the room and it would affect the player.
 
W

Wild_West

Guest
I actually JUST solved it I just had to separate the increase gravity part from the same event as the upward gravity reduction, so for a downward elevator it's in the step event and for an upward elevator it's in the collision event.
But that doesn't sound right to me, I mean instance nearest works for enemies. shouldn't it be whatever instance IS nearest to the given coordinates?
 

TheouAegis

Member
Yes it's the nearest instance. And in your case odds are it will never cause issues. But consider this situation:
Code:
         (^_^)
        /-###-\
       |   |  |    Player barely standing on Elevator 2
           |         
          / \
========_/=  \_
Elevator 1    ============
               Elevator 2
The player is standing on Elevator 2, but just barely. Elevator 1 passes close enough to Elevator 2 such that it passes through the player. Now even though the player is on Elevator 2, the nearest elevator is not Elevator 2, but actually Elevator 1. If Elevator 1 moves up while Elevator 2 moves down, then your gravity will be incorrect.


Sure you can design your game so that such scenarios never arise, but then you're designing your game around bad logic. Codes are like theories - even if it works 99% of the time, it's still incorrect.

Another thing: I'm not sure if you're using a state machine to prevent that code from running all the time, but your code as it is would alter gravity in mid-air. if place_meeting(x,y+1,obj_platform doesn't mean "if there is a platform under me", it means "if there will be a platform touching me anywhere after moving down 1 pixel". So you'd hit a platform in mid-air while jumping, trigger that conditional, then carrier will be the platform the player just bumped into and now gravity is messed up.
 
W

Wild_West

Guest
Right I get it now.
and actually got rid of the carrier variable but before that I did draw out the current value of carrier and it was changing to 10006 through 7 and 8 in odd places but only after I fell off, which really confused me.
I definitely don't WANT bad logic it's just hard to get my head around things I think should be working when they end up not.
 
Last edited by a moderator:
Top