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

Player moves instantly instead of going slowly

LSSPLY

Member
I am struggling with a thing. I can't make this object go slowly to an object that is supposed to attract it with another object, so when it touches "TheZone", it should go up slowly until it reaches "traget", but it just teleports there. does anyone know what should i do?
GML:
if place_meeting(x, y, TheZone.mask_index) {
    for (var i = 1; i > 0; i = y - traget.y) {
        y -= 1;
    }
}
 

Ommn

Member
Don't used "for loop" in one step.
you should use step event and used variable to move to target
like this:
create event:
GML:
MoveToTarget=false;
step event:
GML:
if place_meeting(x, y, TheZone.mask_index) {
    MoveToTarget=true;
}
if MoveToTarget {
    y+=sign(target.y-y);
}
good luck
 

LSSPLY

Member
Don't used "for loop" in one step.
you should use step event and used variable to move to target
like this:
create event:
GML:
MoveToTarget=false;
step event:
GML:
if place_meeting(x, y, TheZone.mask_index) {
    MoveToTarget=true;
}
if MoveToTarget {
    y+=sign(target.y-y);
}
good luck
Ure a lifesaver, thank you very much!!!!
 

LSSPLY

Member
Don't used "for loop" in one step.
you should use step event and used variable to move to target
like this:
create event:
GML:
MoveToTarget=false;
step event:
GML:
if place_meeting(x, y, TheZone.mask_index) {
    MoveToTarget=true;
}
if MoveToTarget {
    y+=sign(target.y-y);
}
good luck
one more thing, this code makes the object to go up without stoping, but i need it to stop when it is not touching "TheZone".could you help me please?
 

Ommn

Member
try this:
step event:
GML:
if place_meeting(x, y, TheZone.mask_index) {
    MoveToTarget=true;
}
if MoveToTarget {
    y+=sign(target.y-y);
    if y==target.y{MoveToTarget=false}
}
 
Top