Search Unity

Question Plz help with rotating while moving!

Discussion in 'Scripting' started by KarmelV31, Nov 5, 2020.

  1. KarmelV31

    KarmelV31

    Joined:
    Nov 4, 2020
    Posts:
    1
    I have a 3d character with animations and created moving but she is not rotating while moving help!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Colletions.Generic;
    3. using UnityEngine;
    4.  
    5. Public class ThirdPersonCharacterController : Monobehaviour
    6.  
    7. float speed = 4;
    8. float gravity = 8;
    9.  
    10. Vector3 moved it = Vector3.zero;
    11.  
    12. CharacterController controller;
    13. Animator anim;
    14.  
    15. void start()
    16. {
    17. controller = GetComponent<CharacterController>();
    18. anim = GetComponent<Animator>();
    19. }
    20.  
    21. void Update()
    22. {
    23. Movement();
    24. }
    25.  
    26. void Movement()
    27. {
    28. If(controller.isGrounded)
    29. {
    30. If(Input.GetKey (KeyCode.W))
    31. {
    32. anim.SetBool("running", true);
    33. anim.SetInteger("condition", 1);
    34. moveDir = new Vector3(0, 0, 1);
    35. moveDir *= speed;
    36. moveDir = transform.TransformDirection(moveDir) ;
    37. }
    38.  
    39. If(Input.GetKeyUp(KeyCode.W))
    40. {
    41. anim.SetBool("running", false);
    42. anim.SetInteger("condition", 0);
    43. moveDir = new Vector3(0, 0, 0);
    44. }
    45.  
    46. If(Input.GetKey (KeyCode.S))
    47. {
    48. anim.SetBool("running", true);
    49. anim.SetInteger("condition", 1);
    50. moveDir = new Vector3(0, 0, -1);
    51. moveDir *= speed;
    52. moveDir = transform.TransformDirection(moveDir) ;
    53. }
    54.  
    55. If(Input.GetKeyUp(KeyCode.S))
    56. {
    57. anim.SetBool("running", false);
    58. anim.SetInteger("condition", 0);
    59. moveDir = new Vector3(0, 0, 0);
    60. }
    61.  
    62. If(Input.GetKey (KeyCode.A))
    63. {
    64. anim.SetBool("running", true);
    65. anim.SetInteger("condition", 1);
    66. moveDir = new Vector3(-1, 0, 0);
    67. moveDir *= speed;
    68. moveDir = transform.TransformDirection(moveDir) ;
    69. }
    70.  
    71. If(Input.GetKeyUp(KeyCode.A))
    72. {
    73. anim.SetBool("running", false);
    74. anim.SetInteger("condition", 0);
    75. moveDir = new Vector3(0, 0, 0);
    76. }
    77.  
    78. If(Input.GetKey (KeyCode.D))
    79. {
    80. anim.SetBool("running", true);
    81. anim.SetInteger("condition", 1);
    82. moveDir = new Vector3(1, 0, 0);
    83. moveDir *= speed;
    84. moveDir = transform.TransformDirection(moveDir) ;
    85. }
    86.  
    87. If(Input.GetKeyUp(KeyCode.D))
    88. {
    89. anim.SetBool("running", false);
    90. anim.SetInteger("condition", 0);
    91. moveDir = new Vector3(0, 0, 0);
    92. }
    93. }
    94. moveDir.y - = gravity*
    95. Time.deltaTime;
    96. controller.Move(moveDir *Time.deltaTime);
    97.  
    98. void GetInput()
    99. {
    100. If(controller.isGrounded)
    101. {
    102. If(Input.GetMouseButtonDown (0))
    103. {
    104. If(anim.GetBool("running")== true;
    105. {
    106. anim.SetBool("running", false);
    107. anim.SetInteger("condition", 0);
    108. }
    109. If(anim.GetBool("running")== false)
    110. {
    111.  
    112. }
    113. }
    114. }
    115. }
    116.  
    117. }
    Help plz!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Are you seeing any errors in the console? Did you retype the code above? The function
    start()
    should be capitalized as
    Start()
    ...

    Also, I don't see any rotate code in there. Is that another script?