I using floating point forward and strafing, here's my script: Code (CSharp): Vector3 moveDir; float vertical; //forward, backward float horizontal; //strafing moveDir = (this.transform.forward * vertical) + (this.transform.right * horizontal); the question is, how to get vertical and horizontal value if I already had moveDir? because my AI pathfinder give moveDir value, but I still need vertical and horizontal value so my AI can do Strafing anim.For example: (0,0,1) = [ (1,0,0) * vertical ] + [ (1,0,0) * horizontal ]

I'm not completely sure what your going for here, but if you multiply transform.someDirection with a float... You will get some maths back lol. What exactly do those variables represent in this case? Are you assigning values to vertical and horizontal? The more you explain what your trying to accomplish the easier it is to give you a good answer, and without knowing more I can't say for sure what to try.

Actually I was multiply with camera transform so my movement are based on camera facing. but this is for AI so I multiply with themselves. Here's the full image of explaination: so, for example: AI's point direction is x: 0.5 & z :0.5. and then AI moved to direction x: -0.5 & z 0.5 without facing to move direction (strafing) we can see actually they just move to the left based on their facing.

I'm also not sure what you're asking for, but based on what you've written here, it seems you want to reverse the calculation. For that case, you can imagine those vectors as some sort of mask for the three vector components. Forward only operates on the z axis, right only on the x axis. At least that's true if we don't take the current orientation of the object into account. For the purpose of explanation, lets ignore the rotation for a moment. In this particular scenario, the vectors component values are just factors that scale the corresponding direction (vertical, horizontal). If you want to take rotation into account, you can do the following: Since moveDir is a given value (in world space), you can transform this into the AI's local space. The local space should be aligned with the AI's "look direction". The result is, that the diagonal line of the look/attack direction in your image will be aligned with the local z, hence the example for the move direction is sort of aligned with the local x axis. Then again, it's just a matter of isolating the local x and z values for horizontal and vertical respectively. This should work for any values. If that's not what you're looking for, you'll have to go into a little more detail.

Yeah you right, I have problem with converting moveDir to local vector based on AI look direction, I had tried with subtracting global vector to AI look direction but some output value does not go right

For such purposes, there're built-in methods, the ones for directions are as follows: Transform.TransformDirection and Transform.InverseTransformDirection The former is used for local space of a transform -> world space, the latter for world space -> local space of a transform. There are similar methods for other uses. They're generally really handy and it's worth taking a look at them.

so if I want to do that I must call AI transform and call inverse transform? I've tried that but the output is a bit difference, maybe because it not normalized but I am not sure

For this case I think you should useTransform.InverseTransformPoint instead... I don't think you're after the direction but rather the position. You should also check if movDir is not already a local vector. If it is, you just need to take movDir.x for the horizontal and movDir.z for the vertical. But if movDir is indeed really a world vector, you can probably just get the local value doing: localMovDir = movDir - youCharacter.Transform.position... I think.

Yes, if it's facing direction is its transform's forward direction, then this should be fine. The direction itself it unaffected by any scale, so if you passed a direction that is not normalized, you cannot expect a direction vector that is normalized. If you visualized both, the original world space direction and the transformed local space directions, they'd be visually the exact same line (if you wanted to draw them as lines using their magnitude). As an example, the image you attached in a previous post shows a move direction in world space of (-0.5, 0.0, 0.5). The magnitude of that vector is mag = sqrt((-0.5 * -0.5) + (0.5 * 0.5)) = sqrt (0-25 + 0.25) which is ~ 0.7071. So it's not normalized, because its magnitude != 1. If you transformed that into local space of a transformed that's oriented as shown in your example (rotated by +45 degree around its y-axis), you should receive a local direction of roughly (0.7071, 0.0, 0.0).

Thanks everyone that's really work when I tried to player input and print to console and it is matched, but I am really sorry before, Vertical and horizontal are used in my animation so It should work like throttle (output between -1 ~ 0 ~ 1), I was mistaken explained them worked as a movespeed, it actually throttle for animation. Code (CSharp): void Ingame_UpdateStates_FixedUpdate() { states.inp.horizontal = horizontal; states.inp.vertical = vertical; states.inp.moveAmount = Mathf.Clamp01(Mathf.Abs(horizontal) + Mathf.Abs(vertical)); Vector3 moveDir = camHandler.transform.forward * vertical; moveDir += camHandler.transform.right * horizontal; moveDir.Normalize(); states.inp.moveDirection = moveDir; states.inp.rotateDirection = camHandler.mTransform.forward;; float b = camHandler.mTransform.InverseTransformDirection(moveDir).x; float a = camHandler.mTransform.InverseTransformDirection(moveDir).z; Debug.Log("input ver/hor: " +vertical+"/"+horizontal+" | formula ver/hor :" +a+"/"+b); } I modified it a bit for AI because they use same states script, I make separate class for control and character process: Code (CSharp): void Ingame_UpdateStates_FixedUpdate() { Vector3 moveDir = waypoint() - states.mTransform.forward; moveDir.Normalize(); //moveDir = states.mTransform.InverseTransformPoint(moveDir); horizontal = moveDir.x; vertical= moveDir.z; states.inp.horizontal = horizontal; states.inp.vertical = vertical; states.inp.moveAmount = Mathf.Clamp01(Mathf.Abs(horizontal) + Mathf.Abs(vertical)); states.inp.moveDirection = moveDir; states.inp.rotateDirection = target; } Here's some of my states code, used on both player and AI: Code (CSharp): void MovementNormal() { if (inp.moveAmount > 0.05f) rigid.drag = 0; else rigid.drag = 4; float speed = stats.walkSpeed; if (states.isRunning) speed = stats.runSpeed; if (states.isCrouching) speed = stats.crouchSpeed; Vector3 dir = Vector3.zero; dir = mTransform.forward * (speed * inp.moveAmount); rigid.velocity = dir; } void RotationNormal() { if(!states.isAiming) inp.rotateDirection = inp.moveDirection; Vector3 targetDir = inp.rotateDirection; targetDir.y = 0; if (targetDir == Vector3.zero) targetDir = mTransform.forward; Quaternion lookDir = Quaternion.LookRotation(targetDir); Quaternion targetRot = Quaternion.Slerp(mTransform.rotation, lookDir, stats.rotateSpeed * delta); mTransform.rotation = targetRot; } void MovementAiming() { float speed = stats.aimSpeed; Vector3 v = inp.moveDirection * speed; rigid.velocity = v; } void HandleAnimationAll() { //anim.SetBool("Sprinting", states.isRunning); if(w_manager.GetCurrent() != null) anim.SetBool("Aiming", states.isAiming); anim.SetBool("ground", states.onGround); //anim.SetBool("Crouch", states.isCrouching); if (states.isAiming) { HandleAnimationsAiming(); } else { HandleAnimationsNormal(); } } void HandleAnimationsNormal() { float anim_v = inp.moveAmount; anim.SetFloat("vertical", anim_v, 0.15f, delta); anim.SetFloat("horizontal", 0); } void HandleAnimationsAiming() { float v = inp.vertical; float h = inp.horizontal; anim.SetFloat("horizontal", h, 0.2f, delta); anim.SetFloat("vertical", v, 0.2f, delta); } Actually I wrote this based on sharp accent channel, anyway maybe I can do something with localized vector. I will think about it. So the conclusion is modeDir should work as a global vector :facepalm: how do you know 0.7071 owned by X value of vector?

I initially thought that moveDir works by issuing a local vector value, it turns out that after I check moveDir it should be of global value, because the moveDir value is used in rigidbody.addforce. But actually I just want to look for vertical and horizontal values which turns out to be used only to fill the animation value, which I have already posted one level above from here. So it turns out I only need the value to trigger the animation, and if it is diagonal then it should be ver = 0.5 / -0.5 hor = 0.5 / -05 vector inverse is very useful knowledge, thank you for explaining it. But I still haven't found a solution, which seems like I was wrong to explain it earlier. n.b: I use google translate so sorry if it seems too convoluted EDIT: I've discovered that 0.7 0.7 is the max point of diagonal of radius 1.0, so converting into local vector is the answer. I don't need 1.0 1.0 because that outside of radius. How stupid I am I forgot pythagoras theorem even you already explained above. Once again it is because my language barrier and lack of knowledge about magnitude free image hosting

What lenguage do you speak? maybe we can help with that. About this: Code (CSharp): Vector3 move = transform.InverseTransformDirection(agent.desiredVelocity); I could be wrong, but isn't the move.z just telling you how much your animator should go foward, and your mov.x value how much it should go to the side? What are you using, a blend tree? This things are tricky, but I'd almost bet you can do: Code (CSharp): animator.SetFloat("Forward", move.z, 0.1f, Time.deltaTime); animator.SetFloat("Side", move.x, 0.1f, Time.deltaTime);

I speak indonesian, anyway I use my own pathfinding for my final project, it's not perfect and still need fix. And now animation works fine. now what I'm looking for is known, Thanks a lot for you all guys.