// Update is called once per frame public KinematicSteeringOutput updateSteering(DynoSteering ds, float time) { if (sp == null) { sp = GetComponent <SteeringParams>(); position = this.transform.position; velc = new Vector3(0f, 0f, 0f); rotation = 0f; orientation = 0f; } 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); }
public DynoSteering getSteering(Vector3 i_GoalLocation) { ds = new DynoSteering(); //goal = goalObject.getGoal(); direction = i_GoalLocation - transform.position; distance = direction.magnitude; targetSpeed = sp.MAXSPEED; 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 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.velocity; 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); }
// Use this for initialization void Start() { char_RigidBody = GetComponent <Kinematic>(); //seek = GetComponent<DynoSeek>(); arrive = GetComponent <DynoArrive>(); align = GetComponent <DynoAlign>(); /*record and write out speed on timer*/ StartTime = Time.time; FileName = "DynoTimer.txt"; System.IO.File.WriteAllText(@"C:\Grad School\AI\A1\" + FileName, "0"); AppearanceRate = 0.1f; LastDroppedCrumb = 0.0f; bHasGoal = false; ds_wander = new DynoSteering(); toCenterWanderCircle = 10; wanderCircleRad = 5; UpperBoundX = -125; LowerBoundX = -175; UpperBoundZ = 40; LowerBoundZ = -10; SafeZoneGoalScript = GetComponent <Goal>(); }
// Update is called once per frame public DynoSteering getSteering(Vector3 goal) { steering = new DynoSteering(); direction = goal - transform.localPosition; distance = direction.magnitude; Debug.Log(distance); if (distance < changeGoalRadius) { changeGoal = true; return(steering); } if (changeGoal) { changeGoal = false; } steering.force = direction; steering.force.Normalize(); steering.force = steering.force * sp.MAXACCEL; steering.torque = 0f; return(steering); }
// Update is called once per frame public DynoSteering getSteering(Vector3 i_GoalLocation) { //goal = goalObject.getGoal(); ds = new DynoSteering(); //goal.position - transform.position; targetOrientation = charRigidBody.getNewOrientation(i_GoalLocation - transform.position); //rotation = goal.eulerAngles; rotation = targetOrientation - charRigidBody.getOrientation(); rotation = Kinematic.mapToRange(rotation); rotationSize = Mathf.Abs(rotation); targetRotation = sp.MAXROTATION; // 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; } return(ds); }
// Update is called once per frame public KinematicSteeringOutput updateSteering(DynoSteering ds, float time) { steering = new KinematicSteeringOutput(); //perform wander behavior // 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); }
// 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); }
// Update is called once per frame void Update() { // Decide on behavior ds_force = arrive.getSteering(); ds_torque = align.getSteering(); ds = new DynoSteering(ds_force.force, 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); }
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); }
//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; } return(ds); }
// Update is called once per frame void Update() { ks = new KinematicSteering(); ds = new DynoSteering(); // Decide on behavior //seeking_output = seek.updateSteering(); //******seeking_output = arrive.getSteering(); seeking_output = arrive.getSteering(); ds_torque = align.getSteering(); //****** //seeking_output = seek.getSteering(); char_kinematic.setVelocity(seeking_output.velc); // Manually set orientation for now /*Replace these three lines with a dynamic rotation*/ //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc); //char_kinematic.setOrientation(new_orient); //char_kinematic.setRotation(0f); ds.torque = ds_torque.torque; // 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); /*record and write out speed on timer*/ string t = (Time.time - StartTime).ToString(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Grad School\AI\A1\" + FileName, true)) { file.WriteLine(t + " | " + char_kinematic.getVelocity().ToString()); } }
private void kinematicSeekBehavior() { ds = new DynoSteering(); // Decide on behavior //****** seeking_output = seek.getSteering(); //******seeking_output = align.getSteering(); //****** char_kinematic.setVelocity(seeking_output.velc); // Manually set orientation for now /*Replace these three lines with a dynamic rotation*/ //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc); //char_kinematic.setOrientation(new_orient); //char_kinematic.setRotation(0f); ds.torque = ds_torque.torque; // 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); }
void Update() { currentGoalTile = goalComponent.getGoalTile(); currentTile = QuantizeLocalize.Quantize(transform.position, tg); if (prevGoalTile != currentGoalTile) { foreach (TileNode tn in currentPath) { if (tn.isEqual(currentTile)) { continue; } tn.setOffMaterial(); } currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); prevGoalTile = currentGoalTile; // light up all tiles foreach (TileNode tn in currentPath) { if (tn.isEqual(currentGoalTile)) { continue; } tn.setPlanMaterial(); } currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); } // determine how to set force if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); // pop when seek says we've made it into range and seek the next target if (seek.changeGoal) { nextTile = currentPath.Pop(); nextTile.setNextMaterial(); currentGoal = QuantizeLocalize.Localize(nextTile); if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); } else { ds_force = arrive.getSteering(currentGoal); } } } else if (currentPath.Count == 0) { ds_force = arrive.getSteering(currentGoal); } ds_torque = align.getSteering(currentGoal); ds = new DynoSteering(); ds.force = ds_force.force; ds.torque = ds_torque.torque; 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); }
void Update() { // check what the current goal is currentGoalTile = goalComponent.tileGoal; // check if we are at the goal position currentTile = QuantizeLocalize.Quantize(transform.position, tg); // if we're at the goal position, then pick a new goal if (currentTile == currentGoalTile) { Debug.Log("here"); goalSetter.SetNextGoal(); currentGoalTile = goalComponent.tileGoal; // find path to new goal currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); // pick next point to seek currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); } else if (!hasPath) { currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); hasPath = true; } // if we are not at last point on path if (currentPath.Count > 0) { // seek next point on path ds_force = seek.getSteering(currentGoal); // pop when seek says we've made it into range and seek the next target if (seek.changeGoal) { nextTile = currentPath.Pop(); currentGoal = QuantizeLocalize.Localize(nextTile); if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); } else { ds_force = arrive.getSteering(currentGoal); } } } // otherwise, we are approaching the path goal. we should arrive. else if (currentPath.Count == 0) { ds_force = arrive.getSteering(currentGoal); } ds_torque = align.getSteering(currentGoal); ds = new DynoSteering(); ds.force = ds_force.force; ds.torque = ds_torque.torque; 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); }
// Update is called once per frame void Update() { ds = new DynoSteering(); if (bHasGoal) { // Decide on behavior ds_force = arrive.getSteering(); ds_torque = align.getSteering(); } else { Vector3 tempGoal = ds_wander.getWanderGoal(char_RigidBody.getVelocity(), transform.position, toCenterWanderCircle, wanderCircleRad); //, UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ); ds_force = arrive.getSteering(tempGoal); ds_torque = align.getSteering(tempGoal); } 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); /*record and write out speed on timer*/ string t = (Time.time - StartTime).ToString(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Grad School\AI\A1\" + FileName, true)) { file.WriteLine(t + " | " + char_RigidBody.getVelocity().ToString()); } DropCrumb(char_RigidBody.getVelocity()); if (!(CheckInBounds(transform.position, UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ))) { char_RigidBody.setVelocity(char_RigidBody.getVelocity() * -1); //char_RigidBody.setRotation(char_RigidBody.getRotation () * -1); //char_RigidBody.setOrientation(char_RigidBody.getOrientation () - 180); //transform.Rotate (0, 180, 0); //float targetOrientation = char_RigidBody.getNewOrientation ((transform.position + char_RigidBody.getVelocity ())); //char_RigidBody.setRotation (targetOrientation - char_RigidBody.getOrientation ()); //char_RigidBody.setOrientation (targetOrientation); //char_RigidBody.setRotation (char_RigidBody.getRotation () - 180); //char_RigidBody.setOrientation /* * if (CheckInBounds (transform.position + (char_RigidBody.getVelocity () * -1), UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ)) * { * char_RigidBody.setVelocity (char_RigidBody.getVelocity () * -1); * } */ //transform.Rotate (0, 180, 0); //char_RigidBody.setOrientation( char_RigidBody() * (-1) );//char_RigidBody.getNewOrientation())// char_RigidBody.getOrientation() - 180 );//char_RigidBody.getNewOrientation (char_RigidBody.getVelocity ())); //transform.rotation = Quaternion.Euler (0, kso.orientation * Mathf.Rad2Deg * -1 ,0); //char_RigidBody.setRotation(char_RigidBody.getRotation () * -1); } }