Jump to content


Photo

Creating Nodes On Path


  • Please log in to reply
19 replies to this topic

#1 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 10 August 2012 - 03:46 PM

So I have a script that should create a node at each point on a path;

//create_nodes_path(ind)
//creates nodes for an AI to follow on a path
//gets all the needed information
var pth,nodes,obj;
pth=argument0;
nodes=path_get_number(pth);


for(i=0;i<nodes+1;i+=1)
 {
 obj=instance_create(x+path_get_point_x(pth,i),y+path_get_point_y(pth,i),obj_node)
 };

...and the nodes aren't created where the path points should be at all. They seem to be created in entirely random spots.

Edited by Lotias, 11 August 2012 - 02:48 AM.

  • 0

#2 WeebleZeeb

WeebleZeeb

    GMC Member

  • GMC Member
  • 13 posts

Posted 10 August 2012 - 11:45 PM

try making it not relative? remove the x+ and the y+
  • 0

#3 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 10 August 2012 - 11:49 PM

The nodes are now created in random places by the top of the screen - still not where the path is being drawn, or even in the shape of the path.
  • 0

#4 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:10 AM

If the shape of the path is the problem.. Your error is elsewhere. Everything in this code looks fine.
  • 0

#5 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:15 AM

The shape of the path looks normal - nothing is wrong the drawing of it being done. The node itself is not executing any code. Nothing else is interacting with the objects in any way shape or form, and I'm entirely sure there are no conflicting variables. Basically, I'm stumped here.
  • 0

#6 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:26 AM

You say completely random... Are the nodes in the same 'random' spot every time?
  • 0

#7 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:28 AM

I actually fixed that - for some reason, I'd put a path_flip in there. (I must be sleep-coding.)
Now it's in the general shape of the path, just not in the right position. I have no idea why it's not in the right position or how to fix it.

Edited by Lotias, 11 August 2012 - 12:31 AM.

  • 0

#8 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:35 AM

Did you make it relative again? That should work. If not replace x with other.x and same with y.
  • 0

#9 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:38 AM

Still getting the exact same result :dry:
  • 0

#10 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:45 AM

Umm well I know the problem, but idk where it is because I can't see all your code. Either the origin of your path isn't where you think it is or the origin of the object creating the nodes isn't where you think it is. So look for your paths first point, look at the origin of the sprite of the object, or look to make sure the right object is calling that script
  • 0

#11 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 12:48 AM

I have the path being drawn, the first point and origin of the object are at the same place. The same object drawing the path is calling the script. There's probably a related problem, though, I like your train of thought.
  • 0

#12 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 12:57 AM

So the nodes look like the drawn path but are shifted somewhere? Where are they if you could explain? The best I can suggest right now is try debugging by drawing out variables such as the objects x and y and whatever other useful info you can draw to make sure nothing fishy is going on
  • 0

#13 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:08 AM

Instead of explaining, here are three screenshots (red lines traced in via mad paint skills so you can see better);
Posted Image
Posted Image
Posted Image
  • 0

#14 Docopoper

Docopoper

    You are observant!

  • GMC Member
  • 1287 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:22 AM

I'm fairly sure that for paths generated using my scripts - the origin of the path should be at 0,0.

The path should be absolute and scaled to the size of your grid's cells. I thought you were doing that, but... I don't know - that's a weird offset.
  • 0

#15 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 01:22 AM

Post your draw code for the path please? Thats really odd tbh...
  • 0

#16 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:25 AM

draw_self();

draw_path(path_ai,pathx,pathy,0);
That's the draw code. Pathx and pathy are where the object begins the path. No problems there.

When I make it absolute, the path goes off to the top of the screen and the following object veers off the screen. The nodes are created in the same place that they were before.

Edited by Lotias, 11 August 2012 - 01:25 AM.

  • 0

#17 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 01:30 AM

Reace x and y with pathx and pathy in the script in the 1st post? Seems le simple, good luck
  • 0

#18 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:32 AM

New script;
//create_nodes_path(ind,x,y)
//creates nodes for an AI to follow on a path
var pth,nodes,obj,xx,yy;
pth=argument0;
nodes=path_get_number(pth);
xx=argument1;
yy=argument2;

with(obj_node)
 {
 instance_destroy()
 };

for(i=0;i<nodes+1;i+=1)
 {
 obj=instance_create(xx+path_get_point_x(pth,i),yy+path_get_point_y(pth,i),obj_node)
 };

where the script is called;
move_snap(48,1);
x+=24;

pathx=x;
pathy=y;

if (platformer_astar(grd_ai,path_ai,(x-24)/48,(y-24)/48,(obj_player.x)/48,(obj_player.y-24)/48,height,jump,5,irritations)==true)
 {
 path_clean(path_ai)
 path_scale(path_ai,48,48)
 create_nodes_path(path_ai,pathx,pathy)
 path_start(path_ai,6,0,1)
 }
 else
 {
 x=obj_player.x
 y=obj_player.y
 };

same result
  • 0

#19 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 11 August 2012 - 01:40 AM

And you retried making it not relative after you fixed stuff? Idk im stumped
  • 0

#20 Lotias

Lotias

    GMC Member

  • GMC Member
  • 880 posts
  • Version:GM:Studio

Posted 11 August 2012 - 01:41 AM

Making it not relative would require changing the position of the path, which I have no idea how to do, but if someone knows how...

Further information; I used the same script in Docopopo's pathfinding example which uses the same paths and stuff, the same node offset occurs. This makes me think something is wrong with the script.

EDIT:
I SOLVED IT.
I create the nodes before scaling the path, and removed the need of the x and y coordinates - I kept the path absolute and multiplied the x and y by 48.

Edited by Lotias, 11 August 2012 - 02:47 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users