0
\$\begingroup\$

I found a youtube video (Sebastian Lague: Character Creation (E07: Unity character controller)) that has a really good movement script, I understood it and used it for my character.

When I started moving it, I noticed that the character rotates but his blue, red, green vectors are not rotating with him, his forward always stays the same, whereas in the youtube video his vectors rotated with the object, what could i have done wrong here?

 Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    Vector2 inputDir = input.normalized;


    //if (inputDir==new Vector2 (0,1))
    //    transform.eulerAngles = new Vector3(0, Camera.main.transform.eulerAngles.y, 0);
    //Debug.Log(Input.GetAxis("Mouse X"));


    if (inputDir != Vector2.zero)
    {


        float TargetRot = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg;
        transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, TargetRot, ref TurnSmoothVelocity, TurnSmoothTime);

    }

    bool running = Input.GetKey(KeyCode.LeftShift);
    float TargetSpeed;
    if (running == true) TargetSpeed = RunSpeed * inputDir.magnitude;
    else TargetSpeed = WalkSpeed * inputDir.magnitude;
    CurrentSpeed = Mathf.SmoothDamp(CurrentSpeed, TargetSpeed, ref SpeedSmoothVelocity, SpeedSmoothTime);

    transform.Translate(transform.forward * CurrentSpeed * Time.deltaTime, Space.World);

}
\$\endgroup\$
1
\$\begingroup\$

If I understood your question correctly, the problem is that the directional arrows in the scene view aren't rotating with your character. One problem that I can think of off the top of my head is that your coordinate system for the translation arrows is set to global. There's a button at the top of the scene tab that's split in half, clicking on the left half will switch between "pivot" and "center", and clicking the right half will switch between "local" and "global". Try switching the right half to local and see what happens.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.