Support Forum

Where is the endpoint of the path?

Hey! I am browsing through the scripts and a beginner as I am, I cannot find the thing.

The thing: I want an object to move instantly to the Destination Point and play an animation there [since I have a sideview at all times, it is not a Target object’s location, but the closest node to it on the Path Surface. Where do I find that within scripts?

image

Is this an “end” parameter?

How do I move the object there really? Is this the right spot to add that thing, @aron_granberg ?

image

…this edit plays animation in the location of a click itself, not the endPoint of the path Player actually moves to. :frowning:

image

Allrightie! I managed to show the effect within Seeker.cs, but still - the “end” parameter apparently is TargetMover’s position. How do I translate this into position on the graph itself?

Full script as it is now:
https://codeshare.io/5QjBkL

My eyes are squared already.

All I need is to get coordinates of the path’s endpoint and move the effect there…

Basically what I need:

if (endpoint != endpoint)
	{
  	effect.transform.position = endpoint;
  	effect.Play();
  }

You can get the closest point on the graph to a point using

var closestPointOnGraph = AstarPath.active.GetNearest(myPoint).position;

See https://arongranberg.com/astar/docs/usingnodes.html

That sounds like what you want.

1 Like

Right!

This put the effect in the right place.

For some odd reason the IF statement is skipped. If I comment out the first rippleEffect.Play() [which causes the effect to play all the time], the script does not register whether the mouse button is unpressed.
It does print out the ELSE log, though. Any ideas?

image

Hi

I would strongly recommend you not to edit the seeker script to add your game’s functionality. Do this from wherever you set the destination of the agent instead.

GetMouseButtonUp will only return true during the single frame where the user released the button, but StartPath is not guaranteed to be called during that frame.

1 Like

Oh, I see.

I guess the last question then, while I have you here:

Would it be the best way then to define public var within seeker and then use another script to call out that var and do the stuff? TargetMover script perhaps?

You should not modify the seeker script.
Somewhere in your game you assign the target the agent is moving to. Have your logic there instead.

Sometimes it makes sense to modify the scripts the pathfinding package has, but in this case it seems like you want to create a ripple effect whenever the user clicks a particular spot. Then that should be handled in the place which actually receives the user input.
If you are using the built-in TargetMover script then that’s where I’d put it. Though I would actually recommend that you duplicate the target mover script instead of modifying the one in the pathfinding package, otherwise whenever you upgrade you will run into problems if both you and I have modified the script.

1 Like

Oh, and I just saw that you had posted a review as well. Sorry about the response delay, I’ve been super busy these last few weeks and I haven’t quite been able to answer posts in the forum as quickly as I would have liked.

1 Like

Agh, yes. I’ll gladly edit that. I do get, that you are just one person. I think I’ll have a reason to bump that star up, so, don’t be mad just yet :slight_smile:

I’ll try to move everything from the Seeker.cs. Now it’s late and tomorrow is the kid-day - I’ll report back on Thursday!

Have a nice evening \m/

1 Like

Is it Thursday already?

Looks like it works like a charm. Now just draw an acceptable art asset for this.

1 Like

I’m glad you solved it :slight_smile:
I hope you are satisfied with the support this time :), even though I was a bit slow to answer in the beginning.

1 Like

Man! It was wonderful! :smiley:

Glad to hear it!
In that case, if it’s not too much trouble, I’d appreciate if you update your review to more accurately reflect your views on the package :slight_smile:

1 Like

I know :wink:
You cought me off computer. Will gladly do that once I get home :slight_smile:

1 Like