HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Click To Move  (Read 1254 times)

1d20Interactive

  • World Owners
  • ****
  • Posts: 1
    • View Profile
[Resolved] Click To Move
« on: Apr 04, 13, 01:47:27 AM »

Sorry, I'm sure this must have been asked before, but I couldn't find anything in the FAQs or search. I'm also very new to Hero Engine.


I want to do a game with an RTS-like movement system -- a fixed overhead camera where movement of a unit is accomplished by clicking on the terrain to order the unit to a specific location.


First step would be handling the mouse input:

I see there are some ray-casting external functions, but I'm not clear on how I should use them. What is the correct way to translate a mouse click on the screen to the specific co-ordinate on the heightmap node that is under the mouse?

Second step would be having a pathfinding system programatically move an entity towards the desired location by navigating along a computed path (avoiding obstacles, etc):

What systems should I use to make this happen? Is this something that ACCC should be used for?

Any help is much appreciated.



« Last Edit: Apr 22, 13, 05:02:56 PM by HE-Cooper »
Logged

lyncthra

  • World Owners
  • ****
  • Posts: 11
    • View Profile
Re: Click To Move
« Reply #1 on: Apr 05, 13, 02:10:22 PM »

Hey, I'm working on a 3rd person click-to-move (like in Dragon Age... you click the ground to move there.) I have no idea if I'm on the right path, or that our paths should be the same, but I'll share with you where I am and hopefully we can help each other or someone will help us both.

So far, in the client script "Input_Mouse," I've got:

Code: [Select]
function OnMouseClick(lmb as Boolean, rmb as Boolean, mmb as Boolean, mb4 as Boolean, mb5 as Boolean) as Boolean
  // I need to add an If statement here. If lmb is true, it's a left click. If rmb is true, it's a right-click, etc
  $INPUT.InputDoMouseClick(GetNodeUnderMouse(), lmb, rmb, mmb, mb4, mb5)
  heightmap as NodeRef = getnodeundermouse()
  target as Vector3
  if not GetGroundUnderMouse(target, heightmap)
    return false
  .
  //println(target)
  playerCharacter as NodeRef of Class HBNode = GetPlayerCharacterNode()
  println(playercharacter["position"])
  // So far, for me, "target" is the xyz on the ground where I have clicked. playercharacter["position"] is my character's current xyz. I'm passing this info to a script on the server.
  call server cmdLincthraClassMethods:testing(playercharacter,playercharacter["position"],target)
  return true
.

In that server script, I've got:

Code: [Select]
untrusted remote function testing(account as NodeRef,pointa as Vector3, pointb as Vector3)
  handler as NodeRef of Class _abstractPathSystemHandler = CreateNodeFromClass("MyPathSystemHandler")
  defaultGroundedHandle as ID = $PathSystem._pathSystem_GetWalkableParameterSetHandle()
  var requestID = $PathSystem._PathSystemGetPath(handler, defaultGroundedHandle, pointA, pointB)
  println(requestid)
.

To get the above working, I did have to create a new S. Class that had a parent class of _abstractPathSystemHandler. I've called it MyPathSystemHandler because the wiki I was piecing together did so. My MyPathSystemHandlerClassMethods script is as follows (almost nothing yet):

Code: [Select]
// The C++ HeroPath system raises this event prior to pathComplete on the $PATHSYSTEM system node which fowards the event to
//   the callback node, allowing the handler the opportunity to merge the calculated path with the current position
//   of the entity for whom the path is intended.  Merging the path will drop points that would make the character go backwards
//   from their current position, ensuring they continue to move towards their goal.
method _PathSystem_PathMerge(pathRequestID as ID, position references Vector3, rotation references Vector3, maxDistance references Float) as Boolean
// Parameters:
//   pathRequestID - Request ID for this request, used internally by the $PATHSYSTEM to map requests to callback nodes
// Returns:
//   position - current position of the enty for whom the path was calculated
//   rotation - current rotation of the entity for whom the path was calculated
//   maxDistance - maximum distance allowed between merge point and nearest point on the path, exceeding the
//                 maximum distance results in no merge and path complete will get the full calculated path
  return false
.

// The C++ HeroPath system raises this event upon the completion of a path on the system node $PATHSYSTEM.
//   The system node then fowards the event to the callback node specified at the time the request was made.
//   The event is the result of a request for a path using $PATHSYSTEM's method _PathSystemGetPath()
method _PathSystem_PathComplete(path as NodeRef of Class _PathSystemResponse)
// Parameters:
//   path - class _PathSystemResponse containing the calculated path
  println("path complete")
.

// Callback made by the $PATHSYSTEM after it has notified the path system handler of a completed path to determine
//   whether or not the system should clean up the node automatically (IE after callback is complete) or allow
//   the path system response node to remain in memory for subsequent use.
method _PathSystem_GarbageCollectPathSystemResponse( path as NodeRef of Class _PathSystemResponse ) as Boolean
  return true
.

I can get it to print the loc I've clicked, print my current character's location, and I can get it to tell me "path complete". I still can't get my character actually moving on the path that it claims it has created. Like I said, I still have a long bit to figure out myself, but hopefully there's -something- there you can use or sparks an idea. I'm still trying to get that path back to the correct client and/or actually set the client actually moving along the path.
« Last Edit: Apr 05, 13, 02:13:48 PM by lyncthra »
Logged

Irushian

  • General Accounts
  • *
  • Posts: 44
    • View Profile
Re: Click To Move
« Reply #2 on: Apr 05, 13, 02:30:14 PM »

Alter the ACCController on the client side to send the movement packets, then other characters will see them move, otherwise they'll just stand still til they reach their destination, and "teleport" even if you see yourself move.

Or are you not seeing movement on the client that is clicking to move?
Logged

lyncthra

  • World Owners
  • ****
  • Posts: 11
    • View Profile
Re: Click To Move
« Reply #3 on: Apr 05, 13, 02:57:10 PM »

I think you are a problem ahead of me. lol. As far as mine goes, the client that clicked isn't actually moving yet. I think I need to perhaps add a listener of some sort to the client and then send the path on the listener? To be honest I was still kind of mid working on it when I decided to see what I -have- done could help that other guy.
Logged

Irushian

  • General Accounts
  • *
  • Posts: 44
    • View Profile
Re: Click To Move
« Reply #4 on: Apr 05, 13, 03:16:11 PM »

While I haven't played with the pathfinding part yet, my guess is that it'll return a series of navpoints (vectors)?

To make them move to a 'navpoint' you'd simply set the behave of the character to "move navpoint <vector location here>". Once they get to a navpoint, check for the next and set to that til you reach the end.
Logged

lyncthra

  • World Owners
  • ****
  • Posts: 11
    • View Profile
Re: Click To Move
« Reply #5 on: Apr 05, 13, 10:14:37 PM »

lol Well, I figured out how to get the navpoints from the path system, but they are stuck on the server-side. I can't figure out how to send them to the appropriate client (to then set the navpoints). The _PathComplete callback doesn't allow for passing an account.  *ponders*
Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: Click To Move
« Reply #6 on: Apr 09, 13, 01:30:45 PM »

There isn't an out of the box client side pathing system per se, as the needs would be so different for different games. You can see how NPCs navigate by default using the navmesh, you could write a character controller that had the player do essentially the same thing.
Logged