Esempio n. 1
0
    private void Update()
    {
        if (!wander.getWanderState())
        {
            currentTimeOutOfWander += Time.deltaTime;

            if (currentTimeOutOfWander > maxTimeSinceLeftWander)
            {
                goalSwitcher.SetGoal(GetComponent <DynoWander>().goal.gameObject);
                wander.setWanderState(true);
                currentTimeOutOfWander = 0.0f;
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    public DynoSteering getSteering()
    {
        ds   = new DynoSteering();
        goal = goalObject.getGoal();

        direction = goal.position - transform.position;
        distance  = direction.magnitude;

        if (distance < goalRadius)
        {
            //goalSwitcher.SwitchGoal();

            //Reactivate wander
            GetComponent <DynoWander>().setWanderState(true);

            goalSwitcher.SetGoal(GetComponent <DynoWander>().goal.gameObject);
        }


        if (distance > slowRadius)
        {
            targetSpeed = sp.MAXSPEED;
        }
        else
        {
            targetSpeed = sp.MAXSPEED * distance / slowRadius;
        }

        targetVelocity = direction;
        targetVelocity.Normalize();
        targetVelocity = targetVelocity * targetSpeed;

        ds.force = targetVelocity - charRigidBody.getVelocity();
        ds.force = ds.force / time_to_target;

        if (ds.force.magnitude > sp.MAXACCEL)
        {
            ds.force.Normalize();
            ds.force = ds.force * sp.MAXACCEL;
        }
        ds.torque = 0f;

        return(ds);
    }