Example #1
0
    // Update is called once per frame
    public KinematicSteeringOutput updateSteering(DynoSteering ds, float time)
    {
        position = this.transform.position;

        steering = new KinematicSteeringOutput();

        // make Updates
        position    += velc * time;
        orientation += rotation * time;

        velc        += ds.force * time;
        orientation += ds.torque * time;

        if (velc.magnitude > sp.MAXSPEED)
        {
            velc.Normalize();
            velc = velc * sp.MAXSPEED;
        }

        steering.position    = position;
        steering.orientation = orientation;



        return(steering);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        ds = new DynoSteering();

        // Decide on behavior
        //seeking_output = seek.updateSteering();
        seeking_output = arrive.getSteering();
        //seeking_output = seek.getSteering();
        char_kinematic.setVelocity(seeking_output.velc);

        // Manually set orientation for now
        if (dynoAlign && dynoAlign.enabled)
        {
            ds = dynoAlign.getSteering();
        }
        else
        {
            float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);
            char_kinematic.setOrientation(new_orient);
            char_kinematic.setRotation(0f);
        }

        // Update Kinematic Steering
        kso = char_kinematic.updateSteering(ds, Time.deltaTime);

        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

        if (recordLogs && logWriter && logWriter.enabled)
        {
            logWriter.Write(char_kinematic.getVelocity().magnitude.ToString());
        }
    }
Example #3
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 > 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);
    }
    // Update is called once per frame
    void Update()
    {
        ks = new KinematicSteering();

        ds        = new DynoSteering();
        ds.torque = align.getSteering().torque;

        // Decide on behavior
        //seeking_output = seek.updateSteering();
        seeking_output = arrive.getSteering();
        //seeking_output = seek.getSteering();
        char_kinematic.setVelocity(seeking_output.velc);

        // Manually set orientation for now
        //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);
        //char_kinematic.setOrientation(new_orient);
        //char_kinematic.setRotation(0f);

        // Update Kinematic Steering
        kso = char_kinematic.updateSteering(ds, Time.deltaTime);

        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

        //Logger.instance.WriteToFileKinematic("speed: " + char_kinematic.getVelocity().magnitude + " time: " + Time.time);
    }
    // Update is called once per frame
    void Update()
    {
        // Decide on behavior
        ds = arrive.getSteering();

        // Update Kinematic Steering
        char_RigidBody.AddForce(ds.force * 20);
        char_RigidBody.AddTorque(new Vector3(0f, ds.torque * Mathf.Rad2Deg, 0f));
    }
    // Update is called once per frame
    public DynoSteering getSteering()
    {
        steering = new DynoSteering();

        goal           = goalObject.getGoal();
        steering.force = goal.position - transform.position;
        steering.force.Normalize();
        steering.force  = steering.force * sp.MAXACCEL;
        steering.torque = 0f;

        return(steering);
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        // Decide on behavior
        ds_force  = arrive.getSteering();
        ds_torque = align.getSteering();

        ds        = new DynoSteering();
        ds.force  = ds_force.force;
        ds.torque = ds_torque.torque;

        // Update Kinematic Steering
        kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
        //Debug.Log(kso.position);
        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
    }
Example #8
0
    //public virtual DynoSteering getSteering();

    // Update is called once per frame
    public DynoSteering getSteering()
    {
        goal = goalObject.getGoal();
        ds   = new DynoSteering();
        //goal.position - transform.position;
        targetOrientation = charRigidBody.getNewOrientation(goal.position - transform.position);


        //rotation = goal.eulerAngles;
        rotation     = targetOrientation - charRigidBody.getOrientation();
        rotation     = Kinematic.mapToRange(rotation);
        rotationSize = Mathf.Abs(rotation);

        if (rotationSize < goalRadius)
        {
            return(ds);
        }

        // if we're outside the slow Radius
        if (rotationSize > slowRadius)
        {
            targetRotation = sp.MAXROTATION;
        }
        else
        {
            targetRotation = sp.MAXROTATION * rotationSize / slowRadius;
        }

        // Final target rotation combines speed (already in variable) with rotation direction
        targetRotation = targetRotation * rotation / rotationSize;

        ds.torque = targetRotation - charRigidBody.getRotation();
        ds.torque = ds.torque / time_to_target;

        angularAcceleration = Mathf.Abs(ds.torque);

        if (angularAcceleration > sp.MAXANGULAR)
        {
            ds.torque = ds.torque / angularAcceleration;
            ds.torque = ds.torque * sp.MAXANGULAR;
        }


        Logger.instance.WriteToFileDynamic("angular acceleration: " + angularAcceleration + " time: " + Time.time);

        return(ds);
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        ks = new KinematicSteering();
        ds = new DynoSteering();

        // Decide on behavior
        //seeking_output = seek.updateSteering();
        //seeking_output = seek.getSteering();


        //seeking_output = arrive.getSteering();
        //char_kinematic.setVelocity(seeking_output.velc);


        //// Manually set orientation for now
        //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);
        //char_kinematic.setOrientation(new_orient);
        //char_kinematic.setRotation(0f);


        Vector3 acceleration = wander.getSteering();

        ds.force = acceleration;

        // Update Kinematic Steering
        kso = char_kinematic.updateSteering(ds, Time.deltaTime);

        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);


        Vector2 direction = new Vector2(char_kinematic.getVelocity().x, char_kinematic.getVelocity().z);
        float   turnSpeed = 20.0f;

        direction.Normalize();

        // If we have a non-zero direction then look towards that direciton otherwise do nothing
        if (direction.sqrMagnitude > 0.001f)
        {
            float toRotation = (Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg);
            float rotation   = Mathf.LerpAngle(transform.rotation.eulerAngles.y, toRotation, Time.deltaTime * turnSpeed);

            transform.rotation = Quaternion.Euler(0, rotation, 0);
        }

//        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
    }
Example #10
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);
    }
Example #11
0
    private void kinematicSeekBehavior()
    {
        ds = new DynoSteering();

        // Decide on behavior
        seeking_output = seek.getSteering();
        char_kinematic.setVelocity(seeking_output.velc);
        // Manually set orientation for now
        float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);

        char_kinematic.setOrientation(new_orient);
        char_kinematic.setRotation(0f);

        // Update Kinematic Steering
        kso = char_kinematic.updateSteering(ds, Time.deltaTime);

        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
    }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        // Decide on behavior
        ds_force = arrive.getSteering();
        //ds_force = wander.getSteering();
        ds_torque = align.getSteering();
        //ds_torque = wander.getSteering();

        ds        = new DynoSteering();
        ds.force  = ds_force.force;
        ds.torque = ds_torque.torque;

        // Update Kinematic Steering
        kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
        //Debug.Log(kso.position);
        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

        //Logger.instance.WriteToFileDynamic("speed: " + char_RigidBody.getVelocity().magnitude + " time: " + Time.time);
    }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        // Decide on behavior
        ds_force  = arrive.getSteering();
        ds_torque = align.getSteering();

        ds        = new DynoSteering();
        ds.force  = ds_force.force;
        ds.torque = ds_torque.torque;

        // Update Kinematic Steering
        kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
        //Debug.Log(kso.position);
        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

        if (recordLogs && logWriter && logWriter.enabled)
        {
            logWriter.Write(char_RigidBody.getVelocity().magnitude.ToString());
        }
    }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        if (isWandering)
        {
            //CheckForWallAndTakeDecision();
        }

        if (isWandering)
        {
            GetWanderGoal();
            ds_force = arrive.getSteering();
            ds       = align.getSteering();
            ds.force = ds_force.force;
        }
        else
        {
            KinematicSteering ks = kinematicArrive.getSteering();

            char_RigidBody.setVelocity(ks.velc);

            //instantly set rotation
            float new_orient = char_RigidBody.getNewOrientation(ds_force.force);
            char_RigidBody.setOrientation(new_orient);
            char_RigidBody.setRotation(0f);
        }

        // Update Kinematic Steering
        kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
        //Debug.Log(kso.position);
        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        float rotation = kso.orientation * Mathf.Rad2Deg;

        transform.rotation = Quaternion.Euler(0f, rotation, 0f);

        if (!isWandering && (arrive.HasArrived() || kinematicArrive.HasArrived()))
        {
            isWandering = true;
        }
    }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        //Check for click
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("Floor")))
            {
                //Get Path
                Vector3 destination = hit.collider.transform.position;
                Vector3 start       = transform.position;
                path        = levelManager.GetShortestPath(start, destination);
                currentGoal = 0;
                isLastGoal  = false;

                if (finalGoal)
                {
                    finalGoal.GetComponent <Renderer>().material = defaultMaterial;
                }

                finalGoal = hit.collider.gameObject;
                finalGoal.GetComponent <Renderer>().material = selected;
            }
        }

        //Update goal positions
        if (currentGoal < path.Count)
        {
            if (seek.HasArrived())
            {
                goalObject.transform.position = path[currentGoal];
                goal.setGoal(goalObject);
                currentGoal++;
                if (currentGoal == path.Count)
                {
                    isLastGoal = true;
                }
            }
        }

        // Decide on behavior
        if (isLastGoal)
        {
            ds_force = arrive.getSteering();
        }
        else
        {
            ds_force = seek.getSteering();
        }
        ds_torque = align.getSteering();

        ds        = new DynoSteering();
        ds.force  = ds_force.force;
        ds.torque = ds_torque.torque;

        // Update Kinematic Steering
        kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
        transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
        transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

        if (recordLogs && logWriter && logWriter.enabled)
        {
            logWriter.Write(char_RigidBody.getVelocity().magnitude.ToString());
        }
    }