Jumping question


Hi I am hoping someone can give me advice on how to handle jumping. Right now I have it so if the node is higher up you can move straight up as if it was a jump instead of doing Move towards through the node, the problem is that it only works if I am one unit away from the node that is higher up. Does anybody know a good way to do this with the Path being taken into account?
Thanks for the help, been struggling with this one and could really use a pointer.

    if (jumping)
        activeUnit.transform.position = Vector3.MoveTowards(new Vector3(activeUnit.transform.position.x, activeUnit.transform.position.y, activeUnit.transform.position.z), (new Vector3(activeUnit.transform.position.x, newTilePosition.position.y, activeUnit.transform.position.z)), .1f);

  if (path != null && activeUnit != null && path[nextPathIdx].position.y > activeUnit.transform.position.y)
                            jumping = true;

(Leslie Young) #2

Why is it a problem that it only works when you are one node away? Do you have units which can jump to something that are further away or maybe i do not understand the problem? An image might help explain it?


What I want to have is something like this in this.

and this as a second example

basically to always be able to know what the next higher up node is when you are next to it no matter where on the path it is.

Right now it only works if i am directly next to the node that I want to jump to when the path starts. I am curious if there is some kind of check I can do to tell what the next higher node will be in the path when I am on the node next to it? Is there a way to find out what the current node a game object is on and next node in the list? Thanks!

(Leslie Young) #4

The returned path is just a list of nodes. So to get the “next” node in the list you simply look ahead one index.

In the code example you posted originally that seems to be done already through path[nextPathIdx]

Maybe I am not understanding correctly what you are asking about. If I refer to the first video for a moment; are you asking about generating the path which will allow the character to reach on top of the pillar or how to use such a path to move the character there?

The samples do not consider units as things you can stand on to reach higher places but that should not be too hard to include as valid moves when calculating the path since you can handle that via the callback the path function makes.


Sorry the first video was a bad example, I am more focused on making it like how it is in the second video right now.

I want it to follow the path but to always be able to jump if the next node in the path list is higher up vertically, at any point of the list index. Thank you for the help and info I appreciate it.

I am sure I will figure it out soon just need to stare at the code a little longer :sunglasses:

(Leslie Young) #6

Scene 4 shows an example where Units can move to tiles which are higher. This example however limit it to how high the Tile may be. Have a look at the source of scene 4.

Pay attention to Sample4Controller.OnNodeCostCallback() and how I passed it to map.Path(). It is what determines what are valid nodes while the path is calculated. Here you will see I do not accept tiles which are higher than 2 steps. So if in your game it must be allowed you need to change that.


I got it working really nicely using some raycasting and some other stuff! Thank you!