Author Topic: Changing path doesn't start from current positon  (Read 47 times)

Offline brockinco

  • Member
  • *
  • Posts: 4
    • View Profile
Changing path doesn't start from current positon
« on: January 07, 2019, 03:26:25 am »
I am using the examples from SWS and trying to implement a game where the player walks down a path and then can turn to the left based on an left arrow keycode. This works to change the path but the character following the path doesn't seems to start the turn from his current position but seems to jump to something like -20 units in the Z direction even though the center line value for path 1 is Z=0 for both waypoint 1 and waypoint 2. For path 2, the first waypoint has a Z=0 value.

Here is a video of the left turn:

https://youtu.be/ZjOlfV3-mYo

Here is the code to change the path based on KeyCode:         

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                SetPath(WaypointManager.Paths["Start"]);
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                SetPath(WaypointManager.Paths["RightTurn"]);
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                SetPath(WaypointManager.Paths["LeftTurn"]);
            }

Offline Baroni

  • Administrator
  • *****
  • Posts: 1381
    • View Profile
Re: Changing path doesn't start from current positon
« Reply #1 on: January 07, 2019, 07:01:49 am »
It looks like the path switch is happening before the end of the path, which is when the movement script tries to interpolate between both paths creating a sharp curve. I can only guess that this is happening since the actual tweens are not visible in your video.

Could you try something:
- set the "moveToPath" variable to true before calling SetPath
- OR, do not position waypoints exactly on top of each other but with a very small offset

Offline brockinco

  • Member
  • *
  • Posts: 4
    • View Profile
Re: Changing path doesn't start from current positon
« Reply #2 on: January 08, 2019, 08:00:07 am »
Thanks for the reply but adding the moveToPath before calling SetPath doesn't seem to work but makes the character jump to unexpected places. I change the code to this:

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                moveToPath = true;
                SetPath(WaypointManager.Paths["ReasonUp-Start"]);
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
           
                moveToPath = true;
                SetPath(WaypointManager.Paths["ReasonUp-RightTurn"]);
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                moveToPath = true;
                SetPath(WaypointManager.Paths["ReasonUp-LeftTurn"]);
            }

So I removed the moveToPath=true calls.

The path switch not happening before the end of the path but at the end. In fact, the character has stopped walking. Notice that when the jump to the left path happens, the character doesn't start on the location of the first waypoint but before it. This is true of the first path as well. It appears that the start point of the path is not being set correctly. Here is another video of the same problem:

https://youtu.be/YYSJk4yGkjA

I have pushed the left and right paths out in the Z direction to show the a distinct space between the center path and the left and right. The paths are shown in blue by the path renderer.

Thanks.
« Last Edit: January 08, 2019, 06:06:20 pm by brockinco »

Offline Baroni

  • Administrator
  • *****
  • Posts: 1381
    • View Profile
Re: Changing path doesn't start from current positon
« Reply #3 on: January 08, 2019, 06:16:27 pm »
Based on this video with more offset, I can only imagine that the paths have some local offset applied to their position? Maybe the WaypointManager itself is not positioned at 0,0,0 or there are more objects parented to the path that do not have a 0,0,0 position?

Since it is difficult to debug this further, I would kindly ask you to send a repro project (in SWS' example scenes would be great) to our email address, so I can get back to you with a more detailed answer.

Offline brockinco

  • Member
  • *
  • Posts: 4
    • View Profile
Re: Changing path doesn't start from current positon
« Reply #4 on: January 08, 2019, 07:10:27 pm »
I would be glad to!

Thanks!

Offline brockinco

  • Member
  • *
  • Posts: 4
    • View Profile
Re: Changing path doesn't start from current positon
« Reply #5 on: January 09, 2019, 02:44:16 am »
Baroni - Thanks but I figured it out based upon your comment about the coordinates of parent object! I found a Z value of 2 units on a parent object that I did not expect. Once I zeroed it out, it works as expected. Thanks so much!