How to make npc just move in x axis?

Hi Aron,

Before, i used version 3
I changed your AI script to :

dir = targetPosition - currentPosition;
dir.y = 0;
dir.z = 0;

so, my npc only move to x axis

now, i use version 4, where i have to change it??
:slight_smile:

thx

Hi

Which version are you using exactly?

If you are using the beta I think you should be able to subclass the AIPath component and override the Move method.

 protected override void Move (Vector3 position3D, Vector3 deltaPosition) {
     deltaPosition.y = 0;
     deltaPosition.z = 0;
     base.Move(position3D, deltaPosition);
 }

If you are using 4.0.10 you can do the same thing, but you will first have to open the AIBase.cs script and make the Move method virtual.

thx for ur answer

now, i using 4.0.10 . But i didn’t find deltaPosition in AI path

i find Move Method like this :
protected override void MovementUpdate (float deltaTime) {
** if (!canMove) return;**

** if (!interpolator.valid) {**
** velocity2D = Vector3.zero;**
** } else {**
** var currentPosition = tr.position;**
…

The Move method exists in the AIBase class, not the AIPath class (AIPath inherits from AIBase).

i have changed Move method in Ai base ,

protected void Move (Vector3 position3D, Vector3 deltaPosition) {
bool positionDirty = false;

		if (controller != null && controller.enabled) {
			// Use CharacterController
			tr.position = position3D;
			deltaPosition.y = 0;
			deltaPosition.z = 0;
			controller.Move(deltaPosition);
			// Grab the position after the movement to be able to take physics into account
			// TODO: Add this into the clampedPosition calculation below to make RVO better respond to physics
			position3D = tr.position;
			if (controller.isGrounded) verticalVelocity = 0;

but my npc still move to all direction. :slight_frown:
pls give me a little more clue. :slight_smile:

Are you using a CharacterController?

i see. i forgot using CharacterController.
Now my npc can move in x axis .
Thank you so much aron. :slight_smile: