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

GML [Resolved] Move object from one point to another

B

BrunoDelfim

Guest
Hello! I'm starting the development of a game for android where the obejto will walk vertically automatically and when clicking on the screen the object goes from one side to the other of the screen, when clicking the object reverses the trajectory, so on, the game has a bar on each side of the screen to keep the object on the screen.

I have already tried many methods, many searched here in the forum, but I can not make object wander from one direction to another until it collides, in the code I made it just disappears from the point where it is and appears colliding with the other bar, and clicak it exits from this point and appears colliding with the other bar.

I need to have a horizontal movement by swapping the direction of the object until it collides, and clicking it changes the direction until it collides with the other bar.

------------------------------------------------------------------------------------------------------------------------------------------------

vsp = 5;
hsp = 8;
vclick = 1;

if mouse_check_button_pressed(mb_left) {

if vclick == 1 {

vclick = 2;
while(!place_meeting(x + hsp, y, obj_BarraLateral)) {
x += hsp;
}

} else {

vclick = 1;
while(!place_meeting(x - hsp, y, obj_Barra)) {
x -= hsp;
}
}
}

y = y - vsp;

------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance!
 

Bentley

Member
I need to have a horizontal movement by swapping the direction of the object until it collides, and clicking it changes the direction until it collides with the other bar.
I'm probably misunderstanding this part of your question, but if by "swapping the direction" you mean the opposite direction, use: direction - 180.
 
Last edited:
B

BrunoDelfim

Guest
In fact, I need to object to the object bar until it crashes.
 
Last edited by a moderator:
B

BrunoDelfim

Guest
The red ball object has to move to one side when clicking with the mouse, the movement must be slow, and when clicking again it should move to the other bar, so on.
 

Attachments

jo-thijs

Member
I'm probably misunderstanding your question, but if by "swapping the direction" you mean the opposite direction, use: direction - 180.
The issue of the OP isn't the turning, but the moving until collision.

Hello! I'm starting the development of a game for android where the obejto will walk vertically automatically and when clicking on the screen the object goes from one side to the other of the screen, when clicking the object reverses the trajectory, so on, the game has a bar on each side of the screen to keep the object on the screen.

I have already tried many methods, many searched here in the forum, but I can not make object wander from one direction to another until it collides, in the code I made it just disappears from the point where it is and appears colliding with the other bar, and clicak it exits from this point and appears colliding with the other bar.

I need to have a horizontal movement by swapping the direction of the object until it collides, and clicking it changes the direction until it collides with the other bar.

------------------------------------------------------------------------------------------------------------------------------------------------

vsp = 5;
hsp = 8;
vclick = 1;

if mouse_check_button_pressed(mb_left) {

if vclick == 1 {

vclick = 2;
while(!place_meeting(x + hsp, y, obj_BarraLateral)) {
x += hsp;
}

} else {

vclick = 1;
while(!place_meeting(x - hsp, y, obj_Barra)) {
x -= hsp;
}
}
}

y = y - vsp;

------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance!
Hi and welcome to the GMC!

You probably meant to use this:
Create event:
Code:
vsp = 5;
hsp = 8;
vclick = 1;
Step event:
Code:
if mouse_check_button_pressed(mb_left) {
    if vclick == 1 {
        vclick = 2;
    } else {
        vclick = 1;
    }
}

if vclick == 1 {
    while(x > xprevious - hsp && !place_meeting(x - 1, y, obj_Barra)) {
        x -= 1;
    }
} else {
    while(x < xprevious + hsp && !place_meeting(x + 1, y, obj_BarraLateral)) {
        x += 1;
    }
}

y = y - vsp;
 
Last edited:
B

BrunoDelfim

Guest
Hello jo-thijs thank you so much!!! That's what I needed, I researched a lot before and could not mount the code. Thank you again!!!
 
Top