Stop Objects from moving on Z-axis in 2D


#1

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?


#2

Which movement script and settings are you using?

Have you looked at the example scenes for 2D?


#3

Yes I’ve followed the video tutorial etc.

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


#4

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


#5

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.


#6

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


#7

Any help on this? turning into quite an issue.


#8

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.


#9

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?


#10

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


#12

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.


#13

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.


#14

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


#15

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


#16

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.


#17

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).


#18

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