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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

how do i make an object go to a certain position?

Discussion in 'Meta-forum Discussion' started by ArvidPiSa05, Oct 13, 2019.

  1. ArvidPiSa05

    ArvidPiSa05

    Joined:
    Oct 11, 2019
    Posts:
    3
    I'm pretty new to Unity and i wonder how i can make an object go to a certain position. I have a button, and in its script i have an empty OnMouseDown thing (not sure what it is called). So i want to make the OnMouseDown to move a game object to a position. How do i do this?
    Edit: I kind of want to make the game object glide to the new position.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,491
    When a mouse button event is triggered, you want to start a method in your script, that performs the move.
    You want to probably use MoveTowards method.

    Here's an example of it, see the Update:
    https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html

    This will make the object glide smoothly over the time to the desired target location.
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,752
    First two posts, both of them about the same and both of them in unrelated forums. Well.

    First, please read this: https://forum.unity.com/threads/unity-community-code-of-conduct.743180/

    Then go here and start to learn the basics: http://learn.unity.com/ (there are free and there are paid courses and tutorials, first, you really need are the free ones for now)