Move Character Controller like transform.translate?

I want to make third person shooter with look camera direction (ex: pubg, resident evil 5). But character controller move method is using global Vector. Can I convert it to Local Vector? Here’s my code:

public void Move(Vector3 movement) //movement vector obtained from global direction from camera face, so the player will move forward depends on camera position
    {
        Debug.Log("is this global :?" +movement); //because it is global, move forward is not always (0,0,1)
        if (inFloor) // check if character standing on the floor
        {
            characterController.SimpleMove(movement * Time.deltaTime * moveSpeed); // it's move based global vector
        }
        if (anim != null) // this is checking animation
        {
            LocalDirection= this.transform.InverseTransformDirection(movement); //I want to convert it to local just like translation method 
            Debug.Log("is this local ?: "+LocalDirection); //printed vector is no different from global
            anim.SetFloat("Vertical", LocalDirection.z); // this should be value of local vector forward
            anim.SetFloat("Horizontal", LocalDirection.x); //this also same, but horizontal so character play strafe animation
        }

        if (movement.magnitude > 0) // i have no idea how to make this work only for turning, but not strafing
        {
            newDirection = Quaternion.LookRotation(movement);
            transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed);
        }
    }

Maybe I should change everything to transform.translate but is that a good idea? so I don’t need character controller components?

Oh boy, I think I’ve reached problems that huge developer struggle.

The character controller will always move on global vectors. But you can convert to local.

Make a new variable to hold your movement as if it were a local variable, then, when you call move, give it the following:

Character.Move(transform.right * move.x + transform.up * move .y + transform.forward * move.z);

This assumes your move vector already has your speed and time.deltaTime factored in and simply converts it to local by multiplying each axis by a local direction. The result is a vector in world space, but one that’s defined by your character’s local space. This should allow you to treat Move as if it were being passed to transform.translate.

Also, I wouldn’t advise just using translation movements because they don’t respect collisions, and the character controller has several useful functions for movement like being able to tell how steep a surface is with onControllerColliderHit, as well as the ever important isGrounded bool.

1 Like

It was few months ago but thanks for headings up! I appreciate it. I can use Space.self and it’s good for diagonal 3D space i guess

hi, how did you used that space self?

Subtract your character controller’s transform.position, I think.
Oops. I didn’t realize this was an old post.

Yes, as awprojectstudio said. subtracting transform may useful if want to transform based specific object but not in child.

You can do: public void Rotate(Vector3 eulers, Space relativeTo = Space.Self);