Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4239924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:05:55+00:00 2026-05-21T03:05:55+00:00

I am trying to make an Object move to a Cube wich is stored

  • 0

I am trying to make an Object move to a Cube wich is stored in an Array.

The Array is filled with gameObjects with a tag.

I can get the Object to move instantly to the cube, but not slowly like its walking to it.

This is my script:

var moveTo : GameObject;

function Update(){
    print(FindClosestEnemy().name);
}

function FindClosestEnemy():GameObject{

    var chasePoints : GameObject[];
    chasePoints = GameObject.FindGameObjectsWithTag("chasePoint");
    var closest : GameObject;
    var distance = Mathf.Infinity;
    var position = transform.position;

    for(var go: GameObject in chasePoints){
        var diff = (go.transform.position-position);
        var curDistance = diff.sqrMagnitude;
        if(curDistance < distance){
            closest = go;
            moveTo = closest;
            transform.position -= moveTo.transform.position;
            distance = curDistance;
        }
    }
    return closest; 
}

I also tried the Time.deltaTime thing, but then it teleports far away from the cube.

And just converting it to Transform Array isnt working out either 🙁 Any ideas to make this work?

Help is much appreciated 🙂 Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:05:56+00:00Added an answer on May 21, 2026 at 3:05 am

    It looks like you are doing the whole transformation in one frame. You need to pick a velocity and apply it to the object for each frame. You know the from and to. Pick how long you want it to take and update it incrementally. Remember that you cannot be sure there will be 60 frames a second so take that into account.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a ForeignKey refer back to the object itself? I'm trying
I am trying to make a very simple object rotate around a fixed point
I am trying to make asynchronous calls using xmlhttprequest object so it completely works
I'm trying to make an application that keeps an object model in sync with
I'm trying to make a deep copy of an object, including a GregorianCalendar instance.
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to make a list containing different objects. List<Object> list = new ArrayList<Object>();
Trying to make a make generic select control that I can dynamically add elements
I'm trying to make a game (using irrlicht engine with c++) where you can
I am still trying to come to grips with how make an object snap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.