F
frozenwisp
Guest
Can I use pathfinding and the in built physics system and if so how?
var px,py;
px=path_get_point_x(path,waypoint_number) //Here we get the X and Y of the next point and store then into some variables.
py=path_get_point_y(path,waypoint_number)
if point_distance(x,y,px,py)<16 //Here we check if the enemy is near the point
if waypoint_number<path_get_number(path) //And if this is not the last point
{
waypoint_number+=1 //So we can increase the waypoint number, meaning that the enemy will now go towards another point
}
mv_aim_x=px //Aims at the Waypoint
mv_aim_y=py //Aims at the Waypoint
mv_up=0.35 //Go forwards to the Waypoint
mv_down=0
mv_left=0
mv_right=0
thanks ill have a play around with thisWhen I implemented the Pathfind for my game (Process and Process) that uses Physics, I did something like this:
Ok, first things first, you create your path, and reset the variables that will define the behavior of the Enemy, in my case it was waypoint_number
Second: a Path is made of "points", the idea is: make the Enemy go towards the Next Point, To do that, I would get the direction from the player to that point, and then would apply the force towards it. In my case it was a bit simpler because my enemy would move towards where he was aiming. When he gets to the next point, we increase our value, the process is repeated until he gets to the end.
Example:
Of course that there's more code than that, but's up to you and how your enemy works, and the idea is pretty simple, really.Code:var px,py; px=path_get_point_x(path,waypoint_number) //Here we get the X and Y of the next point and store then into some variables. py=path_get_point_y(path,waypoint_number) if point_distance(x,y,px,py)<16 //Here we check if the enemy is near the point if waypoint_number<path_get_number(path) //And if this is not the last point { waypoint_number+=1 //So we can increase the waypoint number, meaning that the enemy will now go towards another point } mv_aim_x=px //Aims at the Waypoint mv_aim_y=py //Aims at the Waypoint mv_up=0.35 //Go forwards to the Waypoint mv_down=0 mv_left=0 mv_right=0
I will give you another cup of tea, and recommend you one of the best assets for Pathfinding that I know, download it here on the MarketPlace, it's free. It turns the weird Grid pathfind into a natural/shorter/nice path. ;D
If you want to see the "final result", here's some gameplay footage of my game, you can see in this video an enemy that keeps walking around the map.