// Update is called once per frame public void DoAtion() { if (agent != null) { if (!agent.pathPending) { agent.destination = enemyTank.transform.position; } if (!agent.pathPending) { freq += Time.deltaTime; if (freq > 0.5) { freq -= 0.5f; // agent.SetDestination(enemyTank.transform.position); agent.CalculatePath(enemyTank.transform.position, agent.path); } aling.SetTarget(agent.path.corners[0]); // if(aling.GetDiffAbs()==0f) seek.Steer(agent.path.corners[0]); } } }
// Update is called once per frame void Update() { if (path != null) { Vector3 target = Vector3.zero; // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path target = path.CalcPositionByDistanceRatio(current_percentage); //float path_len = path.length; float distance = (target - transform.position).magnitude; if (distance < accuracy) { current_percentage += distance_ratio; if (current_percentage > 1.0f) { current_percentage -= 1.0f; } } seek.Steer(target, priority); } }
// Update is called once per frame void Update() { // TODO 2: Agents must avoid any collider in their way // 1- Create your own (serializable) class for rays and make a public array with it // 2- Calculate a quaternion with rotation based on movement vector // 3- Cast all rays. If one hit, get away from that surface using the hitpoint and normal info // 4- Make sure there is debug draw for all rays (below in OnDrawGizmosSelected) float current_angle = Mathf.Atan2(move.movement.x, move.movement.z) * Mathf.Rad2Deg; RaycastHit hit; foreach (RayClass ray in rays) { Vector3 rotation_vector = Quaternion.AngleAxis(current_angle, Vector3.up) * ray.direction; if (Physics.Raycast(transform.position, rotation_vector, out hit, ray.max_distance, mask)) { Debug.DrawRay(move.transform.position, ray.direction * ray.max_distance, Color.green); Vector3 escape_vector = hit.point + hit.normal * avoid_distance; seek.Steer(escape_vector); } else { Debug.DrawRay(move.transform.position, ray.direction * ray.max_distance, Color.red); } } }
public void DoAction() { if (!agent.pathPending) { seek.Steer(agent.path.corners[0]); } }
// Update is called once per frame void Update() { // TODO 2: Agents must avoid any collider in their way // 1- Create your own (serializable) class for rays and make a public array with it // 2- Calculate a quaternion with rotation based on movement vector // 3- Cast all rays. If one hit, get away from that surface using the hitpoint and normal info // 4- Make sure there is debug draw for all rays (below in OnDrawGizmosSelected) //2 - Quaternion like move.cs float angle = Mathf.Atan2(move.movement_vel.x, move.movement_vel.z); Quaternion q = Quaternion.AngleAxis(Mathf.Rad2Deg * angle, Vector3.up); //3- Cast all rays with foreach foreach (MyRay ray in rays) { RaycastHit hitInfo; if (Physics.Raycast(transform.position, q * ray.direction, out hitInfo, ray.length, mask)) { //position + normal * length Vector3 awaySurface = hitInfo.point + hitInfo.normal * avoid_distance; seek.Steer(awaySurface); } } }
public void GoToPoint() { if (agent != null) { if (!agent.pathPending) { agent.destination = reload_place.position; } if (!agent.pathPending) { freq += Time.deltaTime; if (freq >= 0.5f) { // agent.SetDestination(enemyTank.transform.position); agent.CalculatePath(reload_place.position, agent.path); freq = 0f; } //aling.SetTarget(agent.path.corners[0]); // if(aling.GetDiffAbs()==0f) seek.Steer(agent.path.corners[0]); } } }
void Update() { /* * Vector3 diff = move.target.transform.position - transform.position; * * if (diff.magnitude < min_distance) * return; * * diff /= time_to_target; * * move.AccelerateMovement(diff); */ if (timer >= wanderRate) { // Update the target Vector3 randomDirection = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f)); randomDirection.Normalize(); Vector3 circlePosition = transform.position + transform.forward * distanceToCircle; target = circlePosition + randomDirection * circleRadius; timer = 0.0f; } timer += Time.deltaTime; seek.Steer(target); }
// Update is called once per frame void Update() { NavMesh.CalculatePath(transform.position, target.transform.position, NavMesh.AllAreas, path); for (int i = 0; i < path.corners.Length - 1; i++) { Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red); } if (path.corners.Length >= 1) { seek.Steer(path.corners[1]); } else { seek.Steer(transform.position); } }
// Update is called once per frame void Update() { // TODO 2: Agents must avoid any collider in their way // 1- Create your own (serializable) class for rays and make a public array with it // 2- Calculate a quaternion with rotation based on movement vector // 3- Cast all rays. If one hit, get away from that surface using the hitpoint and normal info // 4- Make sure there is debug draw for all rays (below in OnDrawGizmosSelected) Quaternion rot = Quaternion.AngleAxis(move.rotation, move.movement); RaycastHit hit; //rays[0].direction = move.movement; //rays[0].origin = move.transform.position; //rays[0].length = avoid_distance; //if (Physics.Raycast(rays[0].origin, rays[0].direction, out hit, rays[0].length)) //{ // if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Terrain")) // { // aux++; // Debug.DrawLine(rays[0].origin, hit.transform.position, Color.red); // } //} //*************************************** rays.direction = move.movement; rays.origin = move.transform.position; rays.length = avoid_distance; if (Physics.Raycast(rays.origin, rays.direction, out hit, rays.length)) { if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Buildings")) //Como hacer esto con la variable mask? { float dist = Vector3.Distance(rays.origin, hit.point); float closeness = Mathf.Abs(dist / avoid_distance); Debug.DrawLine(rays.origin, hit.transform.position, Color.red); Vector3 go_to; go_to = hit.point + hit.normal * move.movement.magnitude; go_to.Normalize(); go_to *= falloff.Evaluate(closeness); seek.Steer(go_to * speed_multiplier); Debug.DrawLine(hit.point, go_to, Color.cyan); //move.AccelerateMovement(go_to); aux = hit.point; } } //Debug.DrawLine(move.transform.position, Vector3.zero, Color.red); }
// Update is called once per frame void Update() { circle_pos = transform.forward * offset_distance + transform.position; new_target = new Vector3(RandomBinominal(), 0, RandomBinominal()); new_target *= rad; new_target += circle_pos; seek.Steer(new_target); }
// Update is called once per frame void ChangeTarget() { random_point = Random.insideUnitSphere; random_point *= radius; random_point += transform.position + offset; random_point.y = transform.position.y; seek.Steer(random_point); Invoke("ChangeTarget", Random.Range(min_update, max_update)); }
// Update is called once per frame void Update() { if (!move) { move = GetComponent <Move>(); } else { if (Vector3.Distance(transform.position, closest_point) <= min_distance) { current_ratio += ratio_increment; if (current_ratio > 1) { current_ratio = 0; } closest_point = path.CalcPositionByDistanceRatio(current_ratio); } seek.Steer(closest_point); } seek.Steer(closest_point); }
// Update is called once per frame void Update() { float angle = Mathf.Atan2(move.current_velocity[priority].x, move.current_velocity[priority].z); Quaternion q = Quaternion.AngleAxis(Mathf.Rad2Deg * angle, Vector3.up); foreach (my_ray ray in rays) { RaycastHit hit; if (Physics.Raycast(new Vector3(transform.position.x, 1.0f, transform.position.z), q * ray.direction.normalized, out hit, ray.length, mask) == true) { seek.Steer(new Vector3(hit.point.x, transform.position.y, hit.point.z) + hit.normal * avoid_distance); } } }
// Update is called once per frame void Update() { // TODO 3: Check if the tank is close enough to the desired point seek.Steer(closest_point); // If so, create a new point further ahead in the path if ((transform.position - closest_point).magnitude <= 0.1) { current_pos += 0.01f; if (current_pos >= 1) { current_pos = 0; } closest_point = path.CalcPositionByDistanceRatio(current_pos); } }
// Update is called once per frame void Update() { // TODO 2: Agents must avoid any collider in their way // 1- Create your own (serializable) class for rays and make a public array with it RaycastHit hit; Ray myRay = new Ray(move.transform.position, move.movement); if (Physics.Raycast(myRay, out hit, avoid_distance, mask)) { Vector3 distance = hit.point + hit.normal; seek.Steer(new Vector3(distance.x, 0, distance.z)); } // 2- Calculate a quaternion with rotation based on movement vector // 3- Cast all rays. If one hit, get away from that surface using the hitpoint and normal info // 4- Make sure there is debug draw for all rays (below in OnDrawGizmosSelected) }
// Update is called once per frame void Update() { // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path current_point = path.CalcPositionByDistanceRatio(current_ratio); current_distance = current_point - transform.position; if (current_distance.magnitude < min_distance) { current_ratio += ratio_increment; if ((current_ratio) > 1.0f) { current_ratio = 0.0f; } } seek.Steer(current_point); }
// Update is called once per frame void Update() { if (timer >= wanderRate) { // Update the target Vector3 randomDirection = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f)); randomDirection.Normalize(); Vector3 circlePosition = transform.position + transform.forward * distanceToCircle; target = circlePosition + randomDirection * circleRadius; timer = 0.0f; } timer += Time.deltaTime; seek.Steer(move.target.transform.position); }
// Update is called once per frame void Update() { // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path Vector3 distance = transform.position - currpoint; if (distance.magnitude < calcdistance) { curvepoint++; if (curvepoint > math.Curve.PointsCount) { curvepoint = 0; } currpoint = math.Curve.Points[curvepoint].PositionWorld; } seek.Steer(currpoint); }
// Update is called once per frame void Update() { move.target.transform.position = closest_point; // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path Vector3 position = closest_point - transform.position; if (position.magnitude < min_distance) { current_ratio += ratio_increment; if (current_ratio > 1.0f) { current_ratio = 0.0f; } closest_point = path.CalcPositionByDistanceRatio(current_ratio); } else { seek.Steer(closest_point); } }
// Update is called once per frame void Update() { // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path Vector3 position_in_curve = closet_point - transform.position; if (position_in_curve.magnitude < 0.05) // min distance to closet point center { range_distance += 0.05f; //ratio distance if (range_distance > 1.0f) { range_distance = 0.0f; } closet_point = path.CalcPositionByDistanceRatio(range_distance); } else { seek.Steer(closet_point); } }
// Update is called once per frame void Update() { // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path Vector3 position = closest_point - transform.position; if (position.magnitude < min_distance) // min distance to closest point { current_ratio += ratio_increment; //increment ratio distance to reach 1 from range [0,1] if (current_ratio > 1.0f) // if ratio distance reach 1, it becomes 0 to start again from initial point { current_ratio = 0.0f; } closest_point = path.CalcPositionByDistanceRatio(current_ratio); // Returns the position due current ratio } else { seek.Steer(closest_point); } }
public void DoAction() { if (agent != null) { if (!agent.pathPending && agent.remainingDistance < 0.5f) { GotoNextPoint(); } if (!agent.pathPending) { freq += Time.deltaTime; if (freq >= 0.5) { freq = 0f; agent.CalculatePath(seekdest, agent.path); } seek.Steer(agent.path.corners[0]); } } }
// Update is called once per frame void Update() { if (path != null) { Vector3 target = Vector3.zero; target = path.CalcPositionByDistanceRatio(current_percentage); //float path_len = path.length; float distance = (target - transform.position).magnitude; if (distance < accuracy) { current_percentage += distance_ratio; if (current_percentage > 1.0f) { current_percentage -= 1.0f; } } seek.Steer(target, priority); } }
void Update() { // TODO 2: Check if the tank is close enough to the desired point // If so, create a new point further ahead in the path Vector3 target = closestPoint - transform.position; float targetDistance = target.magnitude; if (targetDistance < minDistance) { Debug.Log("New point!"); accumulatedDistanceRatio += distanceRatio; if (accumulatedDistanceRatio > 1.0f) { accumulatedDistanceRatio = 0.0f; } closestPoint = path.CalcPositionByDistanceRatio(accumulatedDistanceRatio); } seek.Steer(closestPoint); }
// Update is called once per frame void Update() { if (!move) { move = GetComponent <Move>(); } else { if (path.status == NavMeshPathStatus.PathComplete) { align.Steer(path.corners[current_point]); if (current_point != path.corners.Length - 1) { seek.Steer(path.corners[current_point]); if (Vector3.Distance(transform.position, path.corners[current_point]) < min_distance) { current_point++; } } else { if (arrive.Steer(path.corners[current_point])) { if (!once) { once = true; } } else { once = false; } } } } }
private void Update() { seek.Steer(random_point); }