x


Make objects walk around randomly.

Hi! So, basically, how can i possible make objects walk around randomly within a choosen area, and avoiding walls and other colliders in a smooth way?

Correct answer woud be if you help me get it working, for all of the characters (about 38). I'm currently trying Certain Logic's Navigation and UnitySteer, can't get it working doh.

more ▼

asked Apr 07 '11 at 03:49 PM

Tommy gravatar image

Tommy
156 20 22 27

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
more ▼

answered Apr 07 '11 at 03:54 PM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

Thank you, this sounds really cool. I've been doing some reading about it, and i've downloaded it, then what? Im on a PC, so i've got a .zip file.

Apr 07 '11 at 04:17 PM Tommy

Um, I seriously don't know much about it... You're going to have to learn it all on your own... Sorry man.

Apr 07 '11 at 10:00 PM Justin Warner

But it did not work for me :(

May 07 at 09:55 PM Unity_Dude!@#
(comments are locked)
10|3000 characters needed characters left

I wrote a script that moves objects randomly in a restricted area. In this case on a plane xz becouse I'm working on a "ship's game", but with a few modifications it'll be usefull. The only bad thing is that the object don't avoid obstacles.

using UnityEngine;
using System.Collections;

public class BotControl : MonoBehaviour {

    public float speed;
    public float area;
    private Vector2 newWayPoint;
    private Vector3 wayPoint;
    private Vector3 oldWayPoint;
    public float timeSmooth;
    private float time;
    private CharacterController controller;
    // Use this for initialization
    void Start () {
       newWayPoint = Random.insideUnitCircle * area;
       wayPoint = new Vector3(newWayPoint.x, transform.position.y, newWayPoint.y);
       controller = GetComponent<CharacterController>();
       oldWayPoint = wayPoint;
    }

    // Update is called once per frame
    void Update () {


       SailRandomly();



    }

    void SailRandomly(){
       //rende lookat() più gradevole alla vista
       Vector3 smoothLookAt = Vector3.Slerp(oldWayPoint, wayPoint, time/timeSmooth);
       time += Time.deltaTime;
       smoothLookAt.y = wayPoint.y;

       //il bot si dirige verso "waypoint" finché non lo raggiunge, poi cambia direzione
       if(Vector3.Distance(transform.position, wayPoint)>20.0f && time/timeSmooth < 1.0f){
         transform.LookAt(smoothLookAt);
         controller.SimpleMove(transform.forward * speed);
       }
       else {
         newWayPoint = Random.insideUnitCircle * area;
         oldWayPoint = wayPoint;
         wayPoint = new Vector3(newWayPoint.x, wayPoint.y, newWayPoint.y);
         transform.LookAt(smoothLookAt);
         controller.SimpleMove(transform.forward * speed);
         time = 0;
       }
    }

    void OnGUI() {

       //GUI.Label(new Rect(Screen.width-400, 0, 400, 200), "" + oldWayPoint.ToString() + " | " + wayPoint.ToString() + " | " + time/timeSmooth);
    }
}
more ▼

answered Nov 26 '12 at 10:45 PM

lollornr gravatar image

lollornr
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1094
x572
x498

asked: Apr 07 '11 at 03:49 PM

Seen: 1812 times

Last Updated: May 07 at 09:55 PM