Gravity Acceleration

S

Smenkare

Guest
Hi i was trying to make gravity acceleration.

This was my idea.

grv = 1;
vsp = vsp + grv;

if (place_meeting(x,y+1,oWall))
{
grv = 1;
}
else
for(i=1; i < 50; i += 1)
{
grv += 0.1 * grv;
}

if (place_meeting(x,y+1,oWall)) && (key_jump)

{
vsp += -120 ;
}


I think i can be retarded, i think about this whole day and i have no idea how to do it. Please be patient with me. I was trying to check if object is on the ground if hes not then gravity will multiply in loop. I couldnt find any thread about gravity acceleration.
 

GMWolf

aka fel666
Why are you changing gravity over time? Is your game about jerks?


Anyhow: on collision, you probably also want to set velocity to 0 so you don't keep moving through the wall.

Next: your loop will happen in a single step, not over multiple steps. So every step you are doing g += 0.1 * g 50 times. Is that what you want?
 
S

Smenkare

Guest
This is the problem. Im moving through the walls. How to change it?
 
S

Smenkare

Guest
yeah but if my vsp = vsp + grv it will always be + number. Am i wrong?
 

GMWolf

aka fel666
for(i=1; i < 50; i += 1)
{
grv += 0.1 * grv;
}
This seems very, very wrong to me.


After 1 step, grv 106.
After 2 steps, grv will be 11388.9
Step 3: 1.21542e+6
Step 4: 1.29e+8
...


What is it you're trying to do with that loop?
 

GMWolf

aka fel666
yeah but if my vsp = vsp + grv it will always be + number. Am i wrong?
Have you read my response?
I literally address that.
Have you tried what I suggested?

Also yes you are wrong, if VSP is negative.

Also those massive grv numbers will cause you to move a huge amount every frame, probably skipping over walls and not detecting collisions.
 
S

Smenkare

Guest
I thought grv will be 5.5 after first step. 5 + (0.1 x 5) no? :///
 
S

Smenkare

Guest
Ok i made something like this. I wanted to get fast in the air, stay there for some time and then go fast on the ground. I think it works. Thank you for your time and your help. Any advices on this?


CREATE
Code:
hsp = 0;
vsp = 0;
grv = 3;


walksp = 40;
runDust = false;
canCreateDust = 1;
is_jump_pressed = false;
is_jump_released = false;
jump_counter = 0;
jump_counter_max = 22;
able_jump = true;
jump_execcuted = false;
jump_acc = false;
PART OF SCRIPT

Code:
var move = key_right - key_left;

hsp = move * walksp;
vsp = vsp + grv;

if(is_jump_pressed)
    {
        jump_counter += 4;
        if(jump_counter >= jump_counter_max)
            {
                is_jump_released = true;
            }
    }
if (place_meeting(x,y+1,oWall))
        {
    able_jump = true;
    }    
        else
        {
            able_jump = false;
        }
    
    

        
    
if (able_jump) && (key_jump) {
            jump_execcuted = true;
            jump_acc = true;
        
}            

    if(jump_execcuted)
    {
    if(is_jump_released)
    {
        var percent = clamp(jump_counter / jump_counter_max, 0.00, 1.00);
        
        vsp +=  -(120 * percent);
        is_jump_pressed = false;
        is_jump_released = false;
        jump_counter = 0;
        jump_execcuted = false;
            }
        }
    

if(jump_acc) && (sign(vsp) > 0)
            {
                for(i=1; i < 10; i++)    
                                    {
                                        grv += 0.01 * grv;
                                    }
                
            }
if(jump_acc) && (sign(vsp) < 0)
            {
                for(i=1; i < 1; i++)    
                                    {
                                        grv -= 0.001 * grv;
                                    }
                
            }

//collision
if(place_meeting(x,y+vsp,oWall))
{
    while(!place_meeting(x,y+sign(vsp),oWall))
        {
            y = y + sign(vsp);
        }
        vsp = 0;
        grv = 3;
        jump_acc = false;
}
y = y + vsp;
 

Nidoking

Member
for(i=1; i < 10; i++) { grv += 0.01 * grv; }
This is a waste of time. Again, this is just looping ten times immediately and multiplying grv by 1.01 each time. You can just multiply by power(1.01, 10) to get the same effect.

for(i=1; i < 1; i++) { grv -= 0.001 * grv; }
I don't believe this actually does anything. i will never be less than one.

(sign(vsp) > 0)
I don't understand the use of sign here. If sign(vsp) > 0, then vsp > 0. That's what the sign function does.

There are some very fundamental things about Game Maker that you don't seem to understand. You may want to revisit your tutorials and try to understand things like steps, loops, and math.
 
Top