Search Unity

How to move rigidbody to point with constant speed?

Discussion in 'Physics' started by BigED, Dec 9, 2014.

  1. BigED

    BigED

    Joined:
    Jul 25, 2013
    Posts:
    16
    Hi all! I am moved my rigidbody (3d) with code below

    Code (CSharp):
    1. transform.position =Vector3.Lerp(transform.position,newVector3(dir.x,dir.y, dir.z),Controller.Speed);
    But it isn't use physics, so sometimes I lose collisions.

    How I can move rigidbody to point (with collisions)?

    Thanks!
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  3. BigED

    BigED

    Joined:
    Jul 25, 2013
    Posts:
    16
    Oh, cool! You help me! it is work! Thanks a lot!
     
  4. NareshKhandla

    NareshKhandla

    Joined:
    Aug 6, 2013
    Posts:
    28
    private var speed : Vector3 = Vector3 (3, 0, 0);
    function FixedUpdate () {
    rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
    }
     
  5. SeasiaInfotechind

    SeasiaInfotechind

    Joined:
    Nov 17, 2014
    Posts:
    32
    Hi,

    transform.position is basically change your object position from one point to another. Since we are not applying any velocity/force on a game object that's why it will not detect any kind of collision using transform.position. Please apply physics to move object from source to destination.

    Thanks