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

Move object from point A to B infinitly

Discussion in 'Scripting' started by MrScriptX, Aug 1, 2014.

  1. MrScriptX

    MrScriptX

    Joined:
    Aug 1, 2014
    Posts:
    10
    Hello,

    I would like someone to explain to me how to make an object move from point A to point B with a C# script. But please give me the exact script and tell how to use it.

    thank you
     
  2. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    MoveObject(pointA, pointB);
     
  3. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Sorry:

    MoveObject(pointA, pointB, toInifinitly);

    My mistake
     
  4. MrScriptX

    MrScriptX

    Joined:
    Aug 1, 2014
    Posts:
    10
    Where do i put that?
     
  5. StopAskingForAccounts

    StopAskingForAccounts

    Joined:
    Nov 26, 2013
    Posts:
    20
    I think you messed order of parameters, its move object to point from point

    Code (csharp):
    1.  
    2. MoveObject(pointB, pointA);
    3.  
     
  6. MrScriptX

    MrScriptX

    Joined:
    Aug 1, 2014
    Posts:
    10
    tells me that there is a parsing error.
     
  7. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
     
    Patrick234 likes this.
  8. kariwmklawm

    kariwmklawm

    Joined:
    Jul 28, 2014
    Posts:
    4
    Hello, what you're asking for is a very simple script:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class MoveTowardsObject : MonoBehaviour
    4. {
    5.     public Transform Target;
    6.     public float MoveToSpeed;
    7.  
    8.     private Transform _transform;
    9.  
    10.     private void Start()
    11.     {
    12.         _transform = transform;
    13.     }
    14.  
    15.     private void FixedUpdate()
    16.     {
    17.         _transform.position = Vector3.MoveTowards(_transform.position, Target.position, MoveToSpeed);
    18.     }
    19. }
    20.  
    Simply drag an object into the Target slot, set a value (greater than one to head towards the object) and you are moving towards an object infinitely.
     
  9. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    576
    And said the Loorda
    "Move everything from here infinitely"
    And bigbang happened.
     
  10. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815

    MoveInfinity(Object, pointB) is better
     
  11. MrScriptX

    MrScriptX

    Joined:
    Aug 1, 2014
    Posts:
    10
    Thank you, but (im a noob) when i use the script it tells me that there is a missing behavior. can you show me how to use it.