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

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