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

How Do I Make A Gameobject Follow The Players Mouse?

Discussion in 'Scripting' started by MammothSaturn83, Apr 10, 2019.

  1. MammothSaturn83

    MammothSaturn83

    Joined:
    Feb 10, 2018
    Posts:
    20
    Hi, i've been making a building system and right now i am trying to make it so that the GhostWall is imported in to the game and then follows the players mouse. This is a 3D game. Can someone please help me?

    -Thanks Nicholas
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Mouse is moving over the 2d surface of the screen. To make objects follow mouse in 3d world you need to define some surface in your game they will move over. For examle, a horizontal plane or a terrain object. After that you just raycast from camera through mouse cursor , find intersection with your predefined surface, and place your about-to-be-built gameobject at that position.
     
  3. MammothSaturn83

    MammothSaturn83

    Joined:
    Feb 10, 2018
    Posts:
    20