The Daily Click ::. Forums ::. Klik Coding Help ::. Moving from point XY to point XY2?
 

Post Reply  Post Oekaki 
 

Posted By Message

Retainer



Registered
  02/06/2005
Points
  218
25th November, 2006 at 06:55:56 -

I'm making a isometric pathfinding engine, and I managed so far to build a working road level editor, which I am very proud of My goal is something of what is used in Transport Tycoon.
I am now working with the pathfinding of the vehicle. In examples with the Pathfinding Object, they use a progressing hidden object which the player walk towards. Instead, I would prefer to have the car in this case, go towards stored X Y coordinates in its alterable values. This would make it easier to pathfind several objects.

The isometric pathfinding works, if I use the hidden object way, so the right coordinates are there. I just can't find a working algorithm that will move an object towards an exact X and Y point.

Love the community
/Retainer

 
Alien Invasion. Going forward!
http://www.create-games.com/project.asp?id=1092

Nuutti



Registered
  26/10/2003
Points
  1364
25th November, 2006 at 09:00:57 -

Use an alterable value of that object to store the angle between object and the coordinates:

Angle = atan( (TargetY-ObjectY) : (TargetX-ObjectX))

That's how you get the angle. I'm not sure how to get it in MMF or tgf or whatever you're using because i havent used it in a while... maybe that advanced maths object or maybe mmf has the atan function built-in.

Howewer, then make the object advance in the direction of the angle:

ObjectX = ObjectX + cos(Angle) * SPEED
ObjectY = ObjectY + sin(Angle) * SPEED

That's how it's about done.. Do that angle finding and object moving every frame.

I am not sure if i completely understood what you meant. And i am not sure if you completely understand what i mean because of my asdfasdf english and such. And because i haven't used MMF in a long time, i can only help with this problem in its mathematical aspects and not really how to code it in mmf. ask again if you don't understand it or have some other problems with it.

Image Edited by the Author.

 
P.S. sorry for my mangled english.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
25th November, 2006 at 10:11:56 -

He wants to move it along a grid.

 
n/a

Nuutti



Registered
  26/10/2003
Points
  1364
25th November, 2006 at 10:15:39 -

hmm yes. i probably misunderstood the problem; and i forgot that there's an extension for calculating the angle between two coordinates.
i even did a mistake on those formulae things up there.

Image Edited by the Author.

 
P.S. sorry for my mangled english.

Retainer



Registered
  02/06/2005
Points
  218
25th November, 2006 at 13:26:45 -



axel : well, I already got the correct X and Y coordinates in the grid, all I have to figure out is to move the object from one XY to another XY, and guarantee that it hits that exact XY so I can advance the pathfinding to the next step.
For example, the object is at 120, 230, and I want it to move to 432, 180.
Nuutti, I tried the technique you describe after reading about it in a 360 degree bullet tutorial.
However, it doesn't seem to work. But I figure it has to do with my personal suck factor. I think I forgot to recalculate it every frame, lol. I will experiment with the technique further when I get home again.
It will eventually result in a very cool set of tutorials about isometric games If this community lacks something, it is tutorials about isometrics.
cheers!


 
Alien Invasion. Going forward!
http://www.create-games.com/project.asp?id=1092

Werbad



Registered
  18/09/2002
Points
  235
26th November, 2006 at 04:55:32 -

You need to use aTan2 to retrieve a correct angle, aTan will only return a value in the range of -90 to 90 if i remember correctly...

 
n/a

Nuutti



Registered
  26/10/2003
Points
  1364
26th November, 2006 at 05:57:39 -

That's right, i didn't remember that mmf has atan2 too. You can do it with atan also, by adding 180 to the angle value in some circumstances, but it's easier with atan2.

-Angle = Atan2(targetY-objectY, targetX-objectX)

So atan2, unlike atan, takes 2 parameters.

Image Edited by the Author.

 
P.S. sorry for my mangled english.

Retainer



Registered
  02/06/2005
Points
  218
26th November, 2006 at 15:42:10 -

YES! It works now! Thank you very much for the support.
Await a very cool isometric construction game tutorial pack coming up Think Sim City 2k, Transport Tycoon, Caesar 2...

 
Alien Invasion. Going forward!
http://www.create-games.com/project.asp?id=1092
   

Post Reply



 



Advertisement

Worth A Click