Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem with Character Controller!

Discussion in 'Scripting' started by Philipp_Programmer_Germany, Apr 8, 2015.

  1. Philipp_Programmer_Germany

    Philipp_Programmer_Germany

    Joined:
    Apr 8, 2015
    Posts:
    9
    I have a big issue with this part of Code:

    Code (CSharp):
    1. // Controlling
    2.        // The Input.GetKey is only for testing!
    3.         if (Input.GetKey(KeyCode.B))
    4.         {
    5.  
    6.             Vector3 dir = transform.TransformDirection(Vector3.forward).normalized * calculateCurrSpeed();
    7.             //dir = transform.TransformDirection(dir);
    8.             //dir.y -= getFallConstant();
    9.             Debug.Log("Direction " + dir);
    10.             Debug.DrawRay(transform.position, dir, Color.red);
    11.             if(Input.GetKey(KeyCode.V))
    12.                 characterController.Move(dir * Time.deltaTime);
    13.         }

    So take a look at the Problem:

    The red line show the Direction of the Vector "dir" but it move's in the direction of the Blue one? And always only along the x Axis, also if i Rotate the Object!
     

    Attached Files:

  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    i dont see a problem, does it do the same when you use transform.forward in Move() ?
     
  3. Philipp_Programmer_Germany

    Philipp_Programmer_Germany

    Joined:
    Apr 8, 2015
    Posts:
    9
    Yes it is the same.. I Don't know where the Problem is -_-

    What i do wrong?!
     
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    are any invisible colliders or a nested hierarchy for the character?
     
  5. Philipp_Programmer_Germany

    Philipp_Programmer_Germany

    Joined:
    Apr 8, 2015
    Posts:
    9
    No there aren't any invisible Colliders, i blevie? How i can find invisible colliders? Also no Colliders in the Herachy of the Object. This is an single Game Object and only have an Single Character Controller?! Do you have any idear?
     
  6. mcapousek

    mcapousek

    Joined:
    Jan 11, 2013
    Posts:
    9
    why not directly: dír = transform.forward; ?
     
  7. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    can you post a screenshot of the hierarchy and the inspector of the player?