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

Jumping from "one way platform"

S

Smenkare

Guest
Hi guys, i have object spear which i can jump from. I have problem with colision. If i jump on spear everything is ok but if i jump from under it i jump higher because player object has more steps with collision event. I think its the problem and i dont know how to handle it. I think that changing y. position of my player object would help but i cant change it. I was trying to change var height but it didnt work too well. Any ideas?


Collision event

Code:
if(vsp > 0)
    {
    
        var height = sPlayer.y - other.y;
        if(height < 0) 
            {
with(other)
        {
            if (spearIn) 
            
                { 
                    
                    spearDest = true;
                    sPlayer.vsp -= 100;
                }
        }
            }
    }
spear step event
Code:
if (place_meeting(x,y,oWall)) && (spearDest == false)
    {    
        hspeed = 0;
        sprite_index = sSpearIn;
        spearIn = true;
    }
    
    if(animation_end()) && (spearDest == false) && (spearIn == true)
            {
                image_speed = 0;
            }
            
    
    
    if(spearDest) 
        {
            
            sprite_index = sSpearDestroy;
            image_speed = 1;
            if(animation_end())
                {
                    instance_destroy();
                }
            
        
        }
i dont think spear event is needed here .
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
A quick fix is simply to use an alarm to ensure that the extra speed is only added once... So, for example:

GML:
if(vsp > 0)
    {
    var height = sPlayer.y - other.y;
    if(height < 0)
        {
        with(other)
            {
            if (spearIn)
                {
                spearDest = true;
                if alarm[0] < 0 sPlayer.vsp -= 100;
                alarm[0] = 5;
                }
            }
        }
    }
You MUST add a comment into the alarm event that you use for this to work though! If you don't then the alarm will not run and will always be -1.
 
S

Smenkare

Guest
It doesnt work, i think that alarm resets with every collision step. Could anyone help me?

Bump
 
Last edited by a moderator:

Nidoking

Member
Put brackets around the part that should only run if the alarm is less than zero. It's basic programming, so I really hope you understand what you're doing and aren't just helplessly pasting what people post and hoping it works without you needing to think about it at all. Given that you put all of four hours of thought into it, I'm going to guess the answer to that is no.
 
S

Smenkare

Guest
I dont know, i was thinking about this whole day, maybe im just stupid but i dont understand why it doesnt work.
Code:
if(vsp > 0) && (colided == false)
    {
 
        var height = sPlayer.y - other.y;
        if(height < 0)
            {
with(other)
        {
            if (spearIn)
         
                {
                 
                    spearDest = true;
                    sPlayer.colided = true;
                    if (sPlayer.alarm[0] < 0)
                    {
                    sPlayer.vsp -= 100;
                    sPlayer.alarm[0] = 5;         
                 
                    }
                 
                 
                }
        }
            }
    }
 
Last edited by a moderator:

TailBit

Member
Note that if there is no alarm 0 event, then it won't count down .. so at least leave a comment in it
 
Top