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. Dismiss Notice

Searched far and wide for a good click to move script, but to no avail

Discussion in 'Scripting' started by Im Your Real Dad, Aug 19, 2014.

  1. Im Your Real Dad

    Im Your Real Dad

    Joined:
    Sep 30, 2013
    Posts:
    4
    What I want to do: create a click to move mechanic just like in Magicka: Wizard Wars. Click a location, move to that location. As my character moves to that location, I am able to rotate my character where it always faces my mouse pointer. I'd also like to have the game's camera control mechanic where it's based on mouse position relative to the character, but let's not get ahead of ourselves. I have a very basic understanding of C# programming, but not enough to figure out this behemoth of a task.

    What I've done so far: I believe I found a pretty good script that forces my character to look at my mouse pointer here:

    http://wiki.unity3d.com/index.php/LookAtMouse

    Now, I've found 2 scripts for click to move, but both with its own problems. One found here:

    http://wiki.unity3d.com/index.php/Click_To_Move_C

    The problem with this one is that it does not allow my character to collide with other objects. I've tried a bunch of box collider/rigid body/character control combinations. Nothing works. Though these 2 scripts together make the mechanic I am looking for if it wasn't for this collider problem.

    The other click to move script is found here:



    You can see the entire script near the end of the vid. This is good; it allows my character to collide with other objects. But when used in conjunction with the LookAtMouse script I posted, it doesn't work properly. It will not rotate my character as it starts moving towards the targeted location.

    I've tried modifying these scripts with my little knowledge and reading documentation, but I can't figure it out... Any advice is greatly appreciated!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
  3. Im Your Real Dad

    Im Your Real Dad

    Joined:
    Sep 30, 2013
    Posts:
    4
    Tons of stuff here. Dunno where to start. Gonna take me a while to interpret all this alien language.
     
  4. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    If you've searched "far and wide" then you would've found this!



    Not only it will teach you how to move an object to clicked position it will help you make a basic enemy AI.
     
    Magiichan likes this.
  5. Im Your Real Dad

    Im Your Real Dad

    Joined:
    Sep 30, 2013
    Posts:
    4
    Ha! I guess you're right. Thanks for finding this for me, this one helped me out. Got exactly what I needed!