|
Hello, I am not asking anyone to write me a script or anything just some sort or pointer or direction to head in. I want to make a script that I would be able to attach to an enemy or something to make it wander or meander around aimlessly and randomly while also avoiding collisions with other objects. Any ideas that I may be able to investigate? Thank you.
(comments are locked)
|
|
In order to make it walk around you'd need to basically do 3 things: 1) Pick a random direction (check out Random.insideUnitCircle in scripting help is a good start if its only 2D movement you are after) 2) Send out a ray in that direction, starting from the object and see if it hit anything (check out Collider.Raycast or Physics.Raycast) 3) If the ray did not hit anything, or if it hit something but it is within the acceptable distance away from the object then add some Force to it (if using a Rigidbody component) or lerp the objects transform (iTween or something would help here) After you made that function you would just randomly call, or call it at an interval to have it meander in different directions. (InvokeRepeating) I'll check this out and see what I can come up with and then share the final script in this thread. Thank you!
Jul 20 '10 at 04:01 PM
Panamamigo
(comments are locked)
|
|
A* might be a good place to start looking: http://www.arongranberg.com/unity/a-pathfinding/ Thank you for your response, but I have already seen this site. It is good path finding indeed, but all that I need is to make a cube or sphere or whatever wander around aimlessly. In that site you have him go to the spot that was clicked.
Jul 20 '10 at 04:40 AM
Panamamigo
@Andrew Ty for the link to Aron's work. I hadn't seen it before. Very sweet.
Jul 20 '10 at 03:36 PM
Julian Glenn
@Panamamigo, the A* pathfinding system doesn't just allow for click-to-navigate-- you will have to implement your own system for the AI to choose a point to walk to, but the pathfinding system will handle the navigation to that point.
Jul 21 '10 at 09:53 PM
Andrew 4
(comments are locked)
|
|
RAIN{indie} is a, free, complete solution for adding pathfinding, movement, sensing, and behavior to any Unity project. To download RAIN{indie}, just click the link and follow the 2 steps. RAIN{indie}: http://rivaltheory.com/downloadindie We put together a compilation of tutorials and documents from the RAIN{indie} AI community that supplements our own support resources http://bit.ly/W47KSO FAQs to learn more about the differences between RAIN{one} and RAIN{indie} as well as many other answers. http://support.rivaltheory.com/documentation/faq Email me jester@rivaltheory.com if you have any questions.
(comments are locked)
|
|
So I have been trying to work out a basic little code to make it wander, (without avoiding collisions yet) but it doesn't seem to be working. This is the code I have worked out so far.
It moves if I set wayPoint to a position in the inspector but it moves only to the right and up. This is probably because Vector2 uses only the x and y axis. My problem is that I do not know how to make something move 2 dimensionally across the x and z axis. Any ideas? Why do I have to set it(wayPoint) to a position before it will work? I would've posted this is a comment but then I wouldn't have been able to insert my code.
(comments are locked)
|
