Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple Collision detection (i don't want physics)

Discussion in 'Scripting' started by texel3d, Sep 23, 2014.

  1. texel3d

    texel3d

    Joined:
    Sep 23, 2014
    Posts:
    3
    Hi,

    I am a very beginner in Unity.
    I have seen this tutorial:
    http://unity3d.com/learn/tutorials/projects/roll-a-ball/set-up

    I have modified it to move my ball like "a car" (not just x and z translation).

    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical")*4.0f;

    if( moveHorizontal > 0 )
    angleRotation += 2.0f;
    else if ( moveHorizontal < 0 )
    angleRotation -= 2.0f;

    Vector3 refDirection = new Vector3(0.0f,0.0f,1.0f);
    motionDirection = Quaternion.AngleAxis(angleRotation, Vector3.up) * refDirection;

    motionDirection.Normalize();
    Vector3 movement = motionDirection*Time.deltaTime*moveVertical;

    rigidbody.MovePosition(transform.position + movement);
    }

    I have 2 problems. In the future i will use a mesh instead of a ball and i don't want my player object to have realistic phisics.
    1) I juste want basic collision. I don't want my ball to have realistic motion. When it enter in collision with a wall, i want it to slide on the wall but i don't want it to bounce (no physical force,...). I don't want my player to move when i don't touch my keyboard. How can i do that ?
    2) When i touch the left or right arrow of my keyboard, my object rotate but when i stop to touch the key, the rotation do not stop immediately. There is a very small latency. What is the cause of the problem ? how can i solve this problem ?

    Thanks.
     
  2. texel3d

    texel3d

    Joined:
    Sep 23, 2014
    Posts:
    3
    i have found how to do what i want. I have use "Infinity" for "Drag" and "Angular Drag".
    But there is still the problem of input.
     
  3. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    What about ticking "isKinematic" in the rigidbody? It basically disables physics on the object.
     
  4. texel3d

    texel3d

    Joined:
    Sep 23, 2014
    Posts:
    3
    "What about ticking "isKinematic" in the rigidbody? It basically disables physics on the object."
    I want basic collision and collision responses. My object must collide with walls and slide on it when i continue to move. With "Infinity". It works.
     
  5. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    isKinematic disables physics, but not the rigidbody.
    But if you are pleased with what you have, then great, good for you.
     
  6. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    If you do not want the default physics given to 2D objects, make sure isKinematic is checked. It will allow you to implement your own physics system (or lack there-of) and apply it to your object.