Search Unity

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,553
    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. 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)