Search Unity

looking for a mouse click & point game object script

Discussion in 'Scripting' started by aaronhm77, Nov 25, 2015.

  1. aaronhm77

    aaronhm77

    Joined:
    Nov 22, 2012
    Posts:
    65
    hello;

    I am wanting to implement an RTS mouse "click & point" game object script for my RTS game that does not work on a nav mesh,

    so that I can click on any game object and then point click on the terrain to send the game object on the point of the terrain and so that the game object stays at the point where it is cliked to go.

    the unity store does not have such an RTS asset.

    if any one has such a script or maybe as a challenge to create one and then share it with the unity members, I would appreciate very much,

    thanks;

    Aaronhm77
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    It sounds like pathfinding is what you are after, not so much point-and-click mouse stuff.

    There are some pathfinding assets on the asset store and there are tons of tutorials on how to accomplish it in Unity without the pathfinding available in the navmesh.
     
  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Why do you not want to use the navmesh system?
     
  4. aaronhm77

    aaronhm77

    Joined:
    Nov 22, 2012
    Posts:
    65
    actually it is "mouse click and point" on game object that i want and so that it works with OUT nav mesh

    i have looked high and low and have been with unity for 3 years and have never seen a point click unless it is with a nav mesh

    i know about he path finding and all that but they are all nav mesh unless one that i do not know of.

    but my whole point whith wanting a mouse click and point is so that i can create a RTS with my RTS camera with a mouse click and point aspect to my game, the way a RTS is supose to be and work

    also if there was an EASY mouse click and point RTS it would be a great asset for unity

    it would be the simplest script but unity does not have it.

    like easy way points or easy path finding etc

    i will try looking at some tutorials maybe i will find it there

    thanks for the reply

    aaronhm7
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    That is why you write it! And with the Unity API it is simple.

    Step 1. For the point-and-click: put a collider on the floor mesh, use Camera.ScreenPointToRay() to raycast into the scene, and see if it hits the floor. If it does, you have a point that you clicked on. There must be 100+ tutorials out there for this by now.

    Step 2. For the go-to-position: make your unit move towards the destination at the speed that it can move at. If it can only move in the direction it's facing, then it has to be turned towards the destination first. Turn it, the move it.

    Step 3. If you want the unit to NOT go through obstacles, then you need pathfinding to find a way around those obstacles. AStar pathfinding is probably the best for this. As I mentioned above, there are absolutely non-Navmesh solutions for this, some of them even in the asset store.
     
  6. aaronhm77

    aaronhm77

    Joined:
    Nov 22, 2012
    Posts:
    65
    thanks for the tips,

    the one task I need for this to work, is that the clicked on game object must stay put when it arrives at its destination, so that I can click on another game object and do the same task so that I can move my soldiers and workers and other game objects all over my game board or scene one peice at a time or if i know how to use the suround box that can work to but for know I just want to mouse click on and point the game object.

    I will consider the advise here you have provided and maybe I can make a script of my own, even though I have never done that before.

    also I have not seen any scripts in the asset store as I have mentioned

    and I have searched and looked but to no avail

    I can copy and paste script but if I tried to wright my own script (which I may try like I said) the worst thing would happen of course is I would fail.

    I will continue to ask around and keep posting until I get or create my own script though, one way or another, I know I will succeed in that.

    thanks

    aaronhm7