GameMaker How to move a object to a coordinate

D

Deityfierezy

Guest
So, im really new with the engine and I have really little experience with java so i ask sorry beforehand for my english and my newbie skills.
Anyway im trying to make a title screen, so I made a sprite with the the tile put it in an object and put it in the first room, I made some lines of code that should go in a step event if im not wrong, but the problem is that the first line is telling me that im missing a argument from the 4 required but I couldnt really tell wath it is, here is the code, I tryed to explain wath i think that everything does, and I dont know if in the end will work for wath i want to do
Code:
if point_distance(obj_title.x, obj_title.y, 608x, 255y) > 1 //this tells the distance from the obj_title to the end point, when that distance is mayor than 1 pixel it should play the next line between brackets
                           
 {
   move_towards_point(608x, 255y, 1); //I belive this is self explanatory and it couldnt be misslead for other comand, it says that the object should move to the coordinates 608x, 255y, at the speed of 1 pixel 

   }

else speed = 0;
//this says if the distance of the the obj_title to the ending point is 0 it should start moving at the speed of 0 pixels, wich equals to make a stop.
Thank you very much
 

CloseRange

Member
608x and 255y arn't variables or numbers.
If you meant 608 times x and 255 times y:
Code:
608 * x
255 * y
if you meant plus, just add a +
however i know you just meant the position (608, 255)
you don't put the x and y in:
Code:
if point_distance(obj_title.x, obj_title.y, 608, 255) > 1 {
   move_towards_point(608, 255, 1);
}
also it's better to do this:
Code:
if point_distance(obj_title.x, obj_title.y, 608, 255) > 1 {
    x = 608;
    y = 255;
}
that will set an objects position directly, it isn't good practice to use the function move_towards_point
 

Jon

Member
**** sorry someone beat me to it while I was typing :) ***


Unless I'm missing something, your main problem is that you can't specify the x and y in the coordinate value.
So point_distance(obj_title.x, obj_title.y, 608x, 255y)
should be point_distance(obj_title.x, obj_title.y, 608, 255)
Likewise, your move_towards_point should be move_towards_point(608, 255, 1)
 
D

Deityfierezy

Guest
I dont know if this against the rules but im breaking my head in order to do this and I dont know why it dosent work, so I managed to do the firt thing that i was asking for with your help, now the thing is that i want that when the tittle reaches 640,100 the object obj_start teleports to 512,640 (its out of screen at first), so at first it was with a collision with obj_title and now is a step but it dosent work with any of them.
Code:
with (obj_title) //with obj_title in order so that the code takes into account the title
{
if position_meeting(640, 100, obj_title) // if obj_title reaches 640, 100 it should do the next code (i think this line its wrong)
   {
    obj_start.x = 512;
    obj_start.y = 640; 
    // obj_start teleports to 512,640
   }

}
thanks a lot and sorry if I break any rules.
 

CloseRange

Member
position_meeting checks if you are colliding with another object. You can't collide with yourself, you want this:

Code:
if x == 640 && y == 100 {
    // code
}
NOTE && means the same thing as 'and'
 
D

Deityfierezy

Guest
I cant make it work, I changed it like this:
Code:
//all this is now in different step from the obj_title
if x == 640 && y == 100 {
    with (obj_start){
    obj_start.x = 512; //and// x= 512
    obj_start.y = 640; //and// y= 640
}
}
I tryed at first with this in a step event in the obj_start:
Code:
with (obj_title){
if x == 640 && y == 100 {
    obj_start.x = 512;
    obj_start.y = 640;
}
}
none of them worked
 
D

Deityfierezy

Guest
could you elaborate wath it does and were I should put it? thank you.
edit: I will search in the help guide of the software, but I will apreciate it anyways.
 

TheouAegis

Member
You just put it in the step event of your title object. It will move on its own toward those coordinates - (512, 640).
 
D

Deityfierezy

Guest
Oh, I alredy figured that, now i was trying to teleport sprite/object that it shows a "press start" when the title reaches the cordinates, anyways thank you very much.
Edit: in the end i think i would use some sort of timer if it is possible, but I would really like to do it in a way that both objects interact with each other.

Edit2: Maybe I would try with a global variable if that makes scence, now is too late in here so tomorrow i will do it and if i manage it, i will post it on here.
 
Last edited by a moderator:
D

dannyjenn

Guest
I cant make it work, I changed it like this:
Code:
//all this is now in different step from the obj_title
if x == 640 && y == 100 {
    with (obj_start){
    obj_start.x = 512; //and// x= 512
    obj_start.y = 640; //and// y= 640
}
}
Your code should be:
Code:
if x == 640 && y == 100 {
    with (obj_start){
    x = 512;
    y = 640;
}
}
(Because you used with.)

My guess is that the issue is rounding. As far as I know, move_towards_point() does not guarantee that the instance's coordinates are going to be round numbers, but your code assumes that they are. Your code should be changed to something like this:
Code:
if round(x) == 640 && round(y) == 100 {
    with (obj_start){
    x = 512;
    y = 640;
}
}
 
D

Deityfierezy

Guest
Thanks you, but for some reason it didnt work, maybe is because it has a scale, dunno.
Anyway at the end I used a global variable an it turned very well, maybe its not the best to do it this way because the global variable it loading every time, but for a little game like this i dont think it would do anything, ok this is how I did it:
1. obj_title create event:
Code:
global.titlereaches=0;
2. obj_title step event:
Code:
if point_distance(obj_title.x, obj_title.y, 640, 100) > 2
   {
   move_towards_point(640, 100, 2);
   
   }
else {
    speed = 0;
    variable_global_set("titlereaches", 1);
}
3. obj_start step event:
Code:
if global.titlereaches == 1 {
    obj_start.x = 640;
    obj_start.y = 512;
    exit;
}
 
Top