Aller au contenu

Photo

How to circumvent pathfinding in scripting movement


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I am currently working on puzzles for my next mod.  I one idea which seems like it could be really fun, but the darn pathfinding is ruining it.

I want to make a creature move in a straight line and stop when it hits a barrier.  This works great when it hits a wall, at the edge of an area, but if the creature can find a path around the obstacle, then it just walks around.

I want to find a way to "dumb down" the creatures.

Here are some ideas that I had but could not find functions to facilitate them:

-If I could have an event that measures if the creature cannot find a direct path then I could script around this probelm.  I tride the line of sight functions, but could not make them work.

-If I could somehow duplicate what happens when the PC is moved by pressing the keyboard keys that make him/her move, then I think I could make this work.

-If there was a function that caused a creature to move in a direction but not execute pathfinding, that would actually be the best.


I am really excited about this puzzle, so any help would be greatly appreciated.

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
There may be an easier way of doing it, but for this I'm thinking you need to make use of Vectors (or "angles"). That will take a higher level of scripting knowledge to get it to work right. Its something I have only really dabbled in, so can't be of much help myself, but I'm sure there are those here who have much better experience with this.

#3
rjshae

rjshae
  • Members
  • 4 485 messages
I had a thought: perhaps you could use trigger regions next to the barriers where you want the creature to stop? The On Client Enter script for the triggers could fire a ClearAllActions to halt the motion, then maybe cause the creature to move to an adjacent waypoint.

#4
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

_Knightmare_ wrote...

There may be an easier way of doing it, but for this I'm thinking you need to make use of Vectors (or "angles"). That will take a higher level of scripting knowledge to get it to work right. Its something I have only really dabbled in, so can't be of much help myself, but I'm sure there are those here who have much better experience with this.


Vectors are how I made the basic movements.  But I use them to make a new location that the creature moves to, and then the pathfinding takes over.

Thanks for the reply.  If you think of anything, let me know.

#5
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

rjshae wrote...

I had a thought: perhaps you could use trigger regions next to the barriers where you want the creature to stop? The On Client Enter script for the triggers could fire a ClearAllActions to halt the motion, then maybe cause the creature to move to an adjacent waypoint.


Yeah, That may be the ticket.  I'll test it out.

#6
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Okay, I think I'm on to something here.



I was looking at the CalcSafeLocation() function and there is a boolean parameter which tells the function if you want to make sure there is a straight line to the safe location it is returning. If there is no location found by the funciton, then the function returns the object's current position.



So I am going to make the search radius very small and set the straight line boolean to True, and set up a loop that keeps looking for a new location along the line I want the creature to walk as long as the function returns a location which is equal to it's current location.



It sounds good on paper. Now to see if it works...

#7
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

M. Rieder wrote...

Okay, I think I'm on to something here.

I was looking at the CalcSafeLocation() function and there is a boolean parameter which tells the function if you want to make sure there is a straight line to the safe location it is returning. If there is no location found by the funciton, then the function returns the object's current position.

So I am going to make the search radius very small and set the straight line boolean to True, and set up a loop that keeps looking for a new location along the line I want the creature to walk as long as the function returns a location which is equal to it's current location.

It sounds good on paper. Now to see if it works...


It didn't work.


Now I am trying a new approach. 

Instead of making a new location the full distance I want the creature to travel.  I will break the trip into many small increments with new locations along the way.  I will check for the validity of these locations.   As soon as one is not valid, the loop with stop and the creature will move to the last valid point. 

This seems more promising as it will use functions  I am more familiar with.

#8
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Depending on how complex your puzzle is, you might be able to fake it using a bunch of waypoints. If you can keep track of where each creature is, and what paths are blocked, then you can tell the creature to walk to the right waypoint (near the block in its path) instead of trying to find a path to its ultimate destination.

#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

Lugaid of the Red Stripes wrote...

Depending on how complex your puzzle is, you might be able to fake it using a bunch of waypoints. If you can keep track of where each creature is, and what paths are blocked, then you can tell the creature to walk to the right waypoint (near the block in its path) instead of trying to find a path to its ultimate destination.


that is another good idea.  If I cannot figure out how to do it by creating linear paths, then I will have to fall back on waypoints or triggers.

#10
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

M. Rieder wrote...

[

Now I am trying a new approach. 

Instead of making a new location the full distance I want the creature to travel.  I will break the trip into many small increments with new locations along the way.  I will check for the validity of these locations.   As soon as one is not valid, the loop with stop and the creature will move to the last valid point. 

This seems more promising as it will use functions  I am more familiar with.


This new approach is promising.  The function now calculates the farthest linear path that leads to a valid object. Now I just need to plug in my command to make the creature walk to that point, throw in a conditional that limits the distance this point can be and I should be there....I hope...

#11
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Okay now things are starting to move. I can make the peasant walk in a straight line until he runs into an obsacle and he will stop instead of circumventing it. Now I have to add a limit to how far he goes. Currently he just walks until he hits something.

#12
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
It works now.



Just in case anyone else ever wants to make someone walk in a straight line and stop when he hits an obstacle without pathfinding taking over, here is a description of what to do.



Use the #inclue "x0_i0_position"



The concept is to test points along the line which the creature is going to walk. I test points spread out at intervals of 0.1. I use a loop that stops as soon as the point being tested is no longer valid. At this point, you know where the farthest straight line distance you can travel in a given direction is. Now all you have to do is script the creature to move to the last valid point along the line of travel and there you go! Circumventing pathfinding!



If anyone is interested, just shoot me a message and I will share the code.