Point/Click Select, Move and Avoidance system - use/comment

Hi, :stuck_out_tongue:

I’ve done a fair bit of asking questions around here and tons of lurking. :slight_smile:

I’d like to offer something back in the form of a Point and Click Selection, Movement and Avoidance system. The scripts are below along with instructions. I’ve tried to mark up my own custom spots so you can edit them out if you want to.

I’m hoping that:

A. Someone finds this useful.

B. Others far more experienced than I, could suggest better ways/more efficient ways/offer comments on the way I’m doing what I’m doing.

I’ll describe the system and also attach a basic project.

In my own top sekrit project, every mobile object on the field has a copy of the same script attached. The actual script and its uses are far more in depth and outside of the movement/selection section. Each object has a character controller AND a box collider.

There is a ground plane/ terrain/ floor, whatever, with a mesh collider. It also has a very simple script telling the GameManager that the mouse is over it. This is used to prevent GUI clickthroughs for movement. The character controller glides over the surface following ups and downs.

Empty GO with a GameManager script attached to handle selections and selection particles.

A prefab particle object to show who is selected and destination. The destination version of this also gets a box collider added in script.

Objects can move independently of each other and each will avoid the other.

Import the package into an empty standard project. Scene already set up with the system functioning and two mobile objects you can control and one static obstacle.

Please check it out. Please feel free to offer up any suggestions/comments/criticism, etc.

I am a VERY novice programmer, bear that in mind! All comments are greatly appreciated.

Jason

EDIT: Package back up, problem fixed! :stuck_out_tongue:

EDIT: version 0-1-1 available. Changed destination code to allow movers to ignore a destination that was not their own. Previously, movers would treat other movers’ destination colliders as obstacles.

176318–6303–$pointclickmoveselectavoidsystem_v0_1_1_418.unitypackage (1.08 MB)

I keep getting issues with unity downloads…

Can you please put the .unitypackage in it’s own folder, and then upload the folder it’s self, not just the .unitypackage alone?

Not sure what you meant by folder. Only thing I could think to do was put it in a zip archive which is attached below :slight_smile:

EDIT : v0-1-1

176654–6320–$pointclickmoveselectavoidsystem_v0_1_1_209.zip (1.08 MB)

If your a novice, I’m a baby… This, is going to be a great learning curve…

If I understand correctly, (I am still going over the script), the object detects being clicked, and then detects the position at which you click next. At that point the script calculates a rotation that makes the object face the point you clicked.

At default the object rotates towards the position, and moves forwards to it. It has “whiskers” that, if activated, cause it to change it’s rotation to move out of the way. After a bit of moving out of the way, the object goes back to default.

Whether or not that is how it works, very cool!

What a wonderful example of raycasting! :smile:

EDIT:

To avoid spam, I am just going to post the rest of my comments in this comment…

Flynn,

You are close. You have the moving object doing the ‘selecting’. The GameManager doe this so as to be able to avoid having objects talk to each other.

If I had to document step by step how you get from having no ‘player’ object selected to the object reaching its destination it would be as follows:

  1. If the mouse is over an object and not over a functional GUI element, that object tells the GameManager it is ok to raycast (sets raycastClick true).

  2. The GameManager SelectionManager() function detects the left or right mouse button down.

  3. The SelectionManager() fires a raycast at the screen position clicked on and gets hit information.

  4. The SelectionManager() stores the gameObject and MoverScript as the selectedFieldObject(Script). It then calls NewSelectionParticles() to create the blue selected object particles.

  5. Now that we have a ‘selectedFieldObject’ any further clicks on the ground plane trigger different logic in the SelectionManager(). The SM() detects ground plane hits and calls NewMove() on the selectedFieldObject.

----- end SelectionManager participation. MoverScript on the selected object handles the rest.

  1. The selectedFieldObject stores the Movement class instance created by NewMove() in the var currentMove.

  2. As long as we are not at our destination or have selected a new destination, currentMove loops in Update() calling currentMove.MovementStep().

  3. currentMove.MovementStep() smoothly rotates us toward our destination while checking whiskers for objects to avoid.

  4. If, say, the left angled whisker hits something, it sends Avoidance() the hit info and the OPPOSITE whisker (right in this case) to give a new rotation angle away from the hit.

  5. Avoidance() is looped until we are past the object hit, then we rotate back towards our destination and keep moving looping currentMove.MovementStep() until we hit another obstacle or our destination.

That’s one scenario. Should help you step through the code in correct order.

And, thanks for your compliemnts :stuck_out_tongue:

Jason

WOw, Great , this will be so useful for the project I am working on, I think I will need to ask lots of questions.

First one though , Can we convert this system to a point click navigation system for first person camera.

for instance , the player click a game object far away and the camera will navigate to that spot?

Thanks

Koko,
Thank you for the incredible example project!

I will need to ask questions too…

I do think I understand your step through, and I will bare it in mind when I continue exploring the script.

I used your ray casting examples to come up with this simple script:

var hit : RaycastHit;
var target : GameObject;

function Update()
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); //  cast a ray
if (Physics.Raycast (ray, hit, 100)) // if we hit something
{
target.transform.position = hit.point;
}
}

All it does is move a gameobject to the point in 3d space that the mouse is “pointing at” via raycasting.

The problem is, The raycast keeps hitting the object that it’s moving - causing the object to continuously zoom towards the camera, then when it gets to a certain distance, the raycast goes through it, and it is set back to ground.

I was wondering, how might I get the raycast to go through the target?

I read something about layers, and raycasts ignoring them… How might I do it with layers? I am looking through your scripts for an answer, but I tried this as well for a more direct one.

Thanks for all the help you have been!

EDIT:

Allright, I figured out that it uses the “ignore raycast” layer.

Is there any way to make another layer that does the same thing as “Ignore Raycast”?, And if so is there any way to make it so that some raycasts are, and are not effected by a certain layer (via a preset on the raycast before it is sent)

OK, so my raycasting, object moving thingy won’t work unless the camera has an orbit script!

Any help?

Oh never mind, it had nothing to do with the script LOL

Flynn,

In the mover script before any raycasts originating from an object I store the objects original layer into a variable, set it to ignore raycasts, then set it back after the raycast. Those are for the obstacle avoidance rays.

search the MoverScript for adjlayer. Adapt it to your script and it should work fine.

Koko

This is definately possible, box.

I wont have time to write anything for a couple days. Check back then or let me know if you work it out on your own :slight_smile:

Koko

I all ready have. I just put the object I was moving into the “ignore raycast” layer. It’s nothing important really, just transforming a screen position to a world position.

WHat you are saying is that it quickly changes the layer the exact frame that it sends the raycast?

I have been through the script, and I have seen what you are talking about, however I concentrated on what I was looking for. Basically, it is only on ignore raycast one frame at a time, so that other raycasts will hit the object, but not the one from the script changing the layer?

Flynn,

The layer change happens around the raycast and on a perframe basis so that it will take raycast hits from other objects. If you look in the mover script you will find it in Movement.Step().

Koko