Search Unity

Simple Physics Vehicle using BoxCollider

Discussion in 'Physics' started by Czar-Man, Jul 14, 2016.

  1. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    Hi, all. So I'm working on a simple class project in which you drive a wrecking ball crane with very simple physics using only a BoxCollider and Rigidbody for movement. Recently, I've noticed my vehicle acting wonky against slopes and inclines, often with low gravity coming from upward slopes or falling over when coming from a downward slope. My goal for this vehicle is to allow it to move & turn reasonably, go smoothly up and down slopes and prevent other objects from adding any force to it.

    Here's what I currently have:


    The vehicle is controlled through the CraneDriving script getting input from movement and turning axes while the following functions are called in FixedUpdate:

    private void Move()
    {

    Vector3 movement = transform.forward * m_MovementInputValue * m_Speed/* * Time.deltaTime*/;
    print("Movement: " + movement);




    m_Rigidbody.AddForce(movement, ForceMode.Acceleration);
    }


    private void Turn()
    {

    float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;

    Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);


    m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);

    }

    Additionally, here's the current Physics settings:

    UnityProjectCurrentPhysicsManager.png


    Any advice on what to do is greatly appreciated, as this project is due in a few days.

    Thanks!
     

    Attached Files:

  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Try adding a Physic Material to the collider and configure the friction settings. Your collider actually don't have any physic material so it's using the default friction values. These might be causing unexpected behaviors at some situations.
     
  3. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    I've been having so much trouble with my vehicle bouncing off of buildings, that I decided to not have any materials for either of them.


    Recently, I've made the object Kinematic, added mesh colliders to the caterpillar tracks and changed the movement code to:

    m_Rigidbody.MovePosition(m_Rigidbody.position + movement);

    So far, it's working a lot better with slopes, and keeping the treads on a different layer that doesn't collide with buildings or walls(while keeping the vehicle's box collider bigger), prevents it from running up too much.

    However, I've still noticed it acting very floaty, especially when descending slopes. It still doesn't seem to fall fast enough either, which leads to the vehicle flipping over easily when colliding with a wall or building.
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Not having materials means that the colliders using the default friction settings, which as far as I know don't represent real-world friction and bouncing behaviors. It's preferible to have PhysicMaterials assigned so you can really control how your object behaves on contacts and collisions.