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

Rigidbody and Mesh Collider Problems in Unity5

Discussion in 'Physics' started by Denis-Valjean, Apr 19, 2015.

  1. Denis-Valjean

    Denis-Valjean

    Joined:
    Mar 25, 2015
    Posts:
    39
    Hi, I am using a character with rigidbody and capsule collider modeled to his bones.

    I got a tree from SpeedTrees free pack and added a mesh collider into it. But my char is running through the tree. If I add a normal capsule collider it does not happen.

    I am using this code to move the char:

    /////////////////////////////////////////////////////////////////////////////
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");

    Vector3 move = new Vector3 (h, 0.0f, v);
    Vector3 moveDirection = transform.TransformDirection (move.normalized);
    playerRigidBody.MovePosition(transform.position+ moveDirection * maximumPlayerSpeed * Time.deltaTime);
    ////////////////////////////////////////////////////////////////////////////

    Am I doing something wrong or is it an issue with mesh collider, speedtree or both??

    Another question: If I check freeze Y position on constraints, with does it freeze the position of a character when its falling from an upper plataform? Whats is the constraint when falling??? I dont understand it yet. Thanks in advance.
     
  2. waythewanderer

    waythewanderer

    Joined:
    Apr 6, 2015
    Posts:
    92
    I don't think it's an issue with the mesh collider. Make sure you move your character in FixedUpdate.

    Checking the freeze Y position will lock your rigidbody's vertical position, as falling takes place in the Y axis. If you check the X and Y freeze positions, then your character will just not move.
     
  3. Denis-Valjean

    Denis-Valjean

    Joined:
    Mar 25, 2015
    Posts:
    39
    Figured out! This ^*^&^&* script was messing it all!!
    Code (CSharp):
    1. void MouseRotatePlayer()
    2.     {
    3.         yRotation += Input.GetAxis ("Mouse X") * lookSensitivity;
    4.         xRotation -= Input.GetAxis ("Mouse Y") * lookSensitivity;
    5.         transform.rotation = Quaternion.Euler (0, yRotation, 0);
    6.  
    7.     }
    It was at update reseting my X rotation all time. Even though, my "current speed value "is still crazy when climbing slopes". Why?