• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GRAVITY IN GAME TOO STRONG

Kivelocity

Member
For the entirety of the time I've been working on my current project, I have been having some issues the gravity, and slope collisions. The gravity of the game works fine as long as vertical speed has been increased beforehand, for example if the player jumps. If the player walks off the side of a platform, it falls down far too fast and makes platforming harder and feel strange to do. Here is the gravity code and slope code.

Gravity:

if !ground
{
vsp += 0.25;
}

Slopes:

while place_meeting(x-4, y, objSlopeLongR)
{
y-=2
ground = true;
image_angle = 23

}
while place_meeting(x-4, y, objSlopeLongL)
{
y-=2
ground = true;
image_angle = -23
}
while place_meeting(x-4, y, objSlopeR)
{
y-=2
ground = true;
image_angle = 45
if hsp <= -4
{
hsp -= 0.05
}

}
while place_meeting(x-4, y, objSlopeL)
{
y-=2
ground = true;
image_angle = -45
if hsp >= 4
{
hsp += 0.05
}
 

YoSniper

Member
If vertical speed being too large is the main issue, I recommend imposing a terminal velocity on your object.

In other words, something like:
Code:
if vsp > 8 {
    vsp = 8;
}
I can't speak to the rest of your code because your description of your problem is very vague. A visual aid would help if the problem persists.
 

Kivelocity

Member
Thanks! I lowered the maximum vsp. I have added sonic-style grinding to my game, but the character just seems to slowly sink through the rails, a pixel every second. I need the player to stay on the rail without sinking and stay aligned to the bar, like in a real sonic game. Here is the code:
Grind.JPG

Code:
//Grinding
var Grind = 0;

if place_meeting(x, y, ObjRail) && vsp >= 0 
{
    vsp -= vsp
    if hit_play == true
    {
        audio_play_sound(SouGrindStart, 5, false)
        audio_play_sound(SouGrind, 2, true)
        hit_play = false
    }
    
        vsp -= vsp*1
        image_angle = 0
        ground = true
        hsp += 0.02
        sprite_index = SprSonicGrind;
        jumping = 0 
        
        with ObjRail
        {
            part_emitter_stream(Sname,emitter1,particle1,1);
            part_emitter_region(Sname,emitter1,objSonic.x,objSonic.x+1,objSonic.y,objSonic.y+1,0,0);
        }
    
    if keyboard_check(ord('X'))
    {
        jumping = 2
        sprite_index = SprSonicJump
        vsp = -5
    }

}
else if !place_meeting(x, y, ObjRailTilt)
{
    hit_play = true
   audio_stop_sound(SouGrind)
}


if place_meeting(x, y, ObjRailTilt)
{
        vsp -= vsp
        if hit_play == true
    {
        audio_play_sound(SouGrindStart, 5, false)
        audio_play_sound(SouGrind, 2, true)
        hit_play = false
    }
        y += hsp*2
        hsp += 0.01
        sprite_index = SprSonicGrind;
        image_angle = -30
}

else if !place_meeting(x, y, ObjRail)
{
    hit_play = true
    audio_stop_sound(SouGrind)
}
 

YoSniper

Member
It sounds to me like your "gravity" is still having an effect on the vsp even when you're grounded.

When you're on the ground or on the rail, you want to set vsp = 0;

That should fix the sinking problem.
 
Top