Stop Objects from moving on Z-axis in 2D

If I have an objects that starts on (10, 10, 0), I set it’s destination to (50, 50, 0). Still during moving from point A to point B, he moves on the Z-axis (even though you can’t see it visually since it’s in 2D). Is there any way I can prevent this?

Which movement script and settings are you using?

Have you looked at the example scenes for 2D?

Yes I’ve followed the video tutorial etc.

I set position like: GetComponent<AiPath>().destination = new Vector3(9.96f, -59.06f, 0);

If you are using 2D, should you not have ‘rotation in 2D’ enabled on the AIPath script?

Does that somehow replace the need to manuallyy add the -90 X rotation? Because using it makes everything break.

Ok seems that was it, guess it’s been updates since last time I worked with this. Ill change all the AI to 0 X rotation and check 2d rotation. Ill let you know if that fixes it.

UPDATE: Checking 2D rotation does not change the fact that the AI randomly moves on the z-axis.

Is it just me or is it the same for you?

Any help on this? turning into quite an issue.

Hi

You shouldn’t need to add any rotation manually.
Hm… I think the video tutorial might be a bit outdated, I really should update it if it says you have to do that for the agent.

I cannot replicate any weird movement on the Z axis. If I set to to some Z depth it stays at that Z coordinate even when moving.

Check out the example scene called “RVO 2D” which has agents configured in a way that works. I just tested it with setting rotation speed to zero and disabling ‘slow when not facing target’ and it works perfectly.
I’m not sure what the difference could be that causes you configuration not to work.

1 Like

Actually, using AILerp instead of AIPath fixes the problem. I dont really need AIPath so AILerp will do just fine.
Did you get it to work with AIPath as well? Or were you testing using AILerp?

I was testing AIPath. That’s what’s in the “RVO 2D” example scene.

Zzz, just remembered that AI Lerp acts really strange. On Start all my NPCs just move to (-0.5, -0.5, 0), even though they dont have any targets set or any custom components. Just Seeker, Funnel and AI Lerp (With a target they act as expected).

Is the RVO 2D included in the free package? because I cannot find it. I only have a single 2D example scene, and it uses AI Lerp.

Ah. That is indeed a bug. The AILerp’s default destination was (0,0,0) and not (infinity,infinity,infinity).
This should not affect anything as long as you set a destination for it though (e.g using the AIDestinationSetter component or accessing the ai.destination property). I haven’t found it because I always test the agents with targets :stuck_out_tongue:

RVO 2D is not included in the free package.

Okay, well I can work around it, I’ll just make sure they always have a target :slight_smile:

You can also set ai.destination = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); to make them behave as they have no target.

1 Like

While AILerp does not move on the Z-axis, it does have some restrictions. I would like to use AI Path.
Even if I:

  • create a new empty scene
  • add a 2D Astar Path Grid
  • add a Gameobject at (0,0,0) with Seeker, funnel modifier, and AI Path
  • add a destination setter with a target at (10,0,0)
  • Check Rotation in 2D on AI Path
  • Turn off Gravity on AI Path
  • Set rotation speed to 0 on AIPath
  • turn off Slow when not Facing target on AI Path (this just breaks the AI completely btw if you turn off rotation)

It still moves on the Z-axis even in this super basic scenario. What could be causing this? The movement on the z-axis seems random.

Hi

I cannot replicate that.
I am using a newer version though which has some changes (you can download the 4.1.19 beta if you want the exact same version that I am using). I made a video which shows how it looks for me:
I cannot see any movement on the Z axis which wasn’t explicitly caused by me moving it manually (except for some floating point errors on the order of 10^-6).

Thank you so much for your effort in helping.

It seems upgrading to the beta has solved the issue,. Z doesnt stay at 0 but only moves w 10^-6 floats, which does not effect my checks that look for z = 0 :slight_smile:

Thanks again

1 Like

I am facing the same issue as well

These floating point errors are large enough to cause objects to miss raycasts. I could fix this by extending AIPath/AIBase and writing my own FinalizePosition, but AIBase does not give access to variables/properties such as accumulatedMovementDelta. Why not give access to these?

I am facing the same issue as well. i am using the latest version of 4.3.43

1 Like