protected override IEnumerator Alarm() { //Debug.Log("Overrided Alarm for Bear started"); agent.speed = runSpeed; float chaseTime = 0.0f; while (true) { float dist = Vec3Mathf.DistanceTo(transform.position, visibleTarget.position); if (dist < attackDistance) { PlayerHealth playerHP = FindObjectOfType <PlayerHealth> (); if (playerHP != null) { playerHP.TakeDamage(30); } animator.SetTrigger("Attack"); agent.ResetPath(); yield return(new WaitForSeconds(0.5f)); } animator.SetTrigger("Walk"); chaseTime += Time.deltaTime; agent.ResetPath(); agent.SetDestination(destination = visibleTarget.position); if (chaseTime > 1.0f && fow.visibleTargets.Count < 1) { break; } yield return(new WaitForSeconds(0.1f)); } agent.ResetPath(); // Debug.Log("Остновка погони, переход в поиск цели"); ChangeCondition(Condition.Safety, "Alarm", "Safety"); }
protected IEnumerator FlyToTheSky() { float speed = 0.1f; agent.enabled = false; traectory.graphCorrection = 200.0f; traectory.CalcGraph(transform.position, destination = eaglePatrolPoint); Vector3 nextP = traectory.GetNextPoint(); transform.rotation = Vec3Mathf.GetDirXY(transform.position, destination); while (Vector3.Distance(transform.position, destination) > 1.0f) { transform.position = Vector3.MoveTowards(transform.position, nextP, 0.5f); //speed += Time.deltaTime; //transform.position = Vector3.MoveTowards(transform.position, destination, speed); //Debug.Log(Vector3.Distance(transform.position, destination)); if (Vector3.Distance(transform.position, nextP) < 0.1f) { nextP = traectory.GetNextPoint(); } yield return(new WaitForEndOfFrame()); } agent.enabled = true; //if (isEnemySpotted) // ChangeCondition(Condition.Alarm, "FlyToTheSky", "Alarm"); //else ChangeCondition(Condition.Safety, "FlyToTheSky", "Safety"); }
protected override IEnumerator Alarm() { TestPointer.instance.target3d = this.transform; if (!model.enabled) { ai.FindAreaCenter(visibleTarget.position); agent.Warp(ai.areaCenter.position); model.enabled = true; } agent.speed = runSpeed; while (fow.visibleTargets.Count > 0) { float dist = Vec3Mathf.DistanceTo(transform.position, visibleTarget.position); if (dist < attackDistance) { PlayerHealth playerHP = FindObjectOfType <PlayerHealth> (); if (playerHP != null) { playerHP.TakeDamage(30); } agent.ResetPath(); yield return(new WaitForSeconds(1f)); } agent.SetDestination(destination = visibleTarget.position); yield return(new WaitForSeconds(0.1f)); } agent.ResetPath(); TestPointer.instance.target3d = null; ChangeCondition(Condition.Safety, "Alarm", "Safety"); }
IEnumerator ChangeRot() { while (true) { transform.rotation = Vec3Mathf.GetDir(transform.position, rabbit.position); yield return(new WaitForSeconds(0.01f)); } }
static public Vector3 GetReverseDir(Vector3 start, Vector3 end, float length = 1, float alpha = 15) { float angle = Vec3Mathf.GetAngle(end, start); float dirX = start.x + Mathf.Cos((angle + 90.0f + alpha) * Mathf.Deg2Rad) * length; float dirZ = start.z + Mathf.Sin((angle + 90.0f + alpha) * Mathf.Deg2Rad) * length; return(new Vector3(dirX, start.y, dirZ)); }
//================================================================================================================================= //================================================================================================================================= protected override IEnumerator Alarm() { TestPointer.instance.target3d = transform; Debug.Log("Режим патрулирования"); if (!agent.enabled) { agent.enabled = true; } float condTime = 0.0f; float angle = Vec3Mathf.GetAngle(transform.position, agent.destination); //Debug.Log(angle); destination = Vec3Mathf.GetCirclePoint(eaglePatrolPos, angle, rad); agent.SetDestination(destination); agent.speed = 60.0f; Debug.Log("Перемещаемся к патрулю"); while (agent.remainingDistance > 6.0f) { yield return(new WaitForSeconds(1.0f)); } Debug.Log("Ожидание"); while (true) { condTime += 0.01f;//Time.deltaTime; if (agent.remainingDistance < remDist) { //Debug.Log(angle); angle += anglePlus; destination = Vec3Mathf.GetCirclePoint(eaglePatrolPos, angle, rad); agent.SetDestination(destination); //Debug.Log("Добавляю угол:" + anglePlus); } //if (condTime >= 5.0f) //{ // isEnemySpotted = false; // Debug.Log("Переход в обычное управление полетом"); // ChangeCondition(Condition.Safety, "Alarm","Safety"); //} if (fow.visibleTargets.Count == 0) { TestPointer.instance.target3d = null; ChangeCondition(Condition.Safety, "Alarm", "Safety"); } if (fow.visibleTargets.Count > 0 && condTime >= 3.0f) { ChangeCondition(Condition.Alarm, "Alarm", "MakeDive"); } agent.speed = runSpeed; Debug.DrawLine(eaglePatrolPos, agent.destination, Color.red); yield return(new WaitForSeconds(0.01f)); } }
public void FindAreaCenter(Vector3 nearWithPos) { foreach (Transform trans in SaveZones) { if (areaCenter == null || Vec3Mathf.DistanceTo(nearWithPos, trans.position) < Vec3Mathf.DistanceTo(nearWithPos, areaCenter.position)) { areaCenter = trans; } } walkBounds.SetBounds(walkWidth, walkLength, areaCenter.position); }
private void Awake() { victimPos = victimTrans.transform.position; predatorPos = predatorTrans.transform.position; alpha = Random.Range(-30.0f, 30.0f); length = Random.Range(10.0f, 55.0f); angle = Vec3Mathf.GetAngle(victimPos, predatorPos); StartCoroutine(DebugLines()); }
public void PlaceObjByGraph(GameObject obj) { //Debug.Log(obj.name); place = ScriptableObject.CreateInstance <PlaceObjectToGround>(); rotCalc = ScriptableObject.CreateInstance <RotationCalculator>(); rotCalc.rectRad = 1.0f; rotCalc.rectRadZ = 1.0f; rotCalc.yMod = 2.0f; rotCalc.maxAngleX = 60.0f; rotCalc.maxAngleZ = 45.0f; //Debug.Log("graph length: "+graphLength); GameObject tempObj; float rnd = 0.2f; for (int i = 0; i < vec3points.Length - 1; i++) { if (i % rar == 0) { tempObj = Instantiate(obj, objsParent); tempObj.transform.position = new Vector3(vec3points[i].x, vec3points[i].y + offset, vec3points[i].z); tempObj.transform.parent = objsParent; rnd = 0.2f; tempObj.transform.rotation = new Quaternion( tempObj.transform.rotation.x, tempObj.transform.rotation.y + Random.Range(-rnd, rnd), tempObj.transform.rotation.z, tempObj.transform.rotation.w ); tempObj.transform.rotation = Vec3Mathf.GetDir(vec3points[i], vec3points[0]); rotCalc.MakeCalculations(tempObj.transform, tempObj.transform); place.corr = corr; place.Place(ref tempObj); } } tempObj = Instantiate(obj, objsParent); tempObj.transform.position = new Vector3(vec3points[vec3points.Length - 1].x, vec3points[vec3points.Length - 1].y + offset, vec3points[vec3points.Length - 1].z); tempObj.transform.parent = objsParent; tempObj.transform.rotation = new Quaternion( tempObj.transform.rotation.x, tempObj.transform.rotation.y + Random.Range(-rnd, rnd), tempObj.transform.rotation.z, tempObj.transform.rotation.w ); //tempObj.transform.rotation = Vec3Mathf.GetDir(vec3points[vec3points.Length - 3], vec3points[vec3points.Length-2]); rotCalc.MakeCalculations(tempObj.transform, tempObj.transform); place.corr = corr; place.Place(ref tempObj); }
void ChooseZone(Transform[] zones) { foreach (Transform zone in zones) { if (finalZone == null || Vec3Mathf.DistanceTo(transform.position, zone.position) < Vec3Mathf.DistanceTo(transform.position, finalZone.position)) { finalZone = zone; } } //Debug.Log(finalZone); areaCenter = finalZone; walkBounds.SetBounds(walkWidth, walkLength, areaCenter.position); }
public IEnumerator DebugLines() { while (true) { angle = Vec3Mathf.GetAngle(startPos, targPos); Debug.DrawLine(startPos, new Vector3(startPos.x + 5.0f, startPos.y, startPos.z), Color.red); // x axis Debug.DrawLine(startPos, new Vector3(startPos.x, startPos.y, startPos.z + 5.0f), Color.blue); // z axis Debug.DrawLine(startPos, GetVec3(graphLength), Color.cyan); // rotation vector CalcGraph(); DrawGraph(); yield return(new WaitForSeconds(0.01f)); } }
static public Quaternion GetDirXY(Vector3 start, Vector3 end) { float angle = Vec3Mathf.GetAngle1(start, end); float angleX = GetAngleXY(start, end); float angleZ = 0.0f; if (angle > 90.0f && angle < 270.0f) { angle = -(180.0f - angle); angleZ = 180.0f; } //Debug.Log(angle + " | " + angleX); return(Quaternion.Euler(angleX, -angle, angleZ)); }
// Update is called once per frame void Update() { start = starttrans.position; end = endtrans.position; Debug.DrawLine(start, end, Color.cyan); Debug.DrawLine(start, new Vector3(start.x + 5.0f, start.y, start.z), Color.red); Debug.DrawLine(start, new Vector3(start.x, start.y, start.z + 5.0f), Color.blue); Debug.DrawLine(start, new Vector3(start.x, start.y + 5.0f, start.z), Color.green); Debug.DrawLine(end, new Vector3(end.x + 5.0f, end.y, end.z), Color.red); Debug.DrawLine(end, new Vector3(end.x, end.y, end.z + 5.0f), Color.blue); Debug.DrawLine(end, new Vector3(end.x, end.y + 5.0f, end.z), Color.green); Debug.Log(Vec3Mathf.GetAngle(start, end, Vector3.up)); }
IEnumerator MoveByCircle() { float angle = 0.0f; agent.SetDestination(Vec3Mathf.GetCirclePoint(startPos, angle, rad)); while (true) { if (agent.remainingDistance < remDist) { angle += 5.0f; agent.SetDestination(Vec3Mathf.GetCirclePoint(startPos, angle, rad)); Debug.Log("Добавляю угол"); } yield return(new WaitForSeconds(0.01f)); } }
private void Update() { if (canvas.enabled) { float distance = Vec3Mathf.DistanceTo(rectTrans.position, menuPoint.position); if (distance > 20) { canvas.enabled = false; } } if (OVRInput.Get(OVRInput.Button.One) && canActive) { rectTrans.position = menuPoint.position; rectTrans.rotation = Quaternion.LookRotation(menuPoint.forward); canvas.enabled = true; } }
Vector3 GetDir(Vector3 start, Vector3 end) { float angle = Vec3Mathf.GetAngle(end, start); float dirX = start.x + Mathf.Cos((angle + 90.0f) * Mathf.Deg2Rad) * length; float dirZ = start.z + Mathf.Sin((angle + 90.0f) * Mathf.Deg2Rad) * length; Vector3 dir = new Vector3(dirX, start.y, dirZ); float dirAX = start.x + Mathf.Cos((angle + 90.0f + alpha) * Mathf.Deg2Rad) * length; float dirAZ = start.z + Mathf.Sin((angle + 90.0f + alpha) * Mathf.Deg2Rad) * length; Vector3 dirA = new Vector3(dirAX, start.y, dirAZ); //float dirA1X = start.x + Mathf.Cos((angle + 90.0f - alpha) * Mathf.Deg2Rad) * length; //float dirA1Z = start.z + Mathf.Sin((angle + 90.0f - alpha) * Mathf.Deg2Rad) * length; //Vector3 dir1A = new Vector3(dirA1X, start.y, dirA1Z); Debug.DrawLine(start, dirA, Color.yellow); //Debug.DrawLine(start, dir1A, Color.magenta); return(dir); }
IEnumerator DebugLines() { while (true) { victimPos = victimTrans.transform.position; predatorPos = predatorTrans.transform.position; Debug.DrawLine(victimPos, new Vector3(victimPos.x, victimPos.y, victimPos.z + 5.0f), Color.blue); Debug.DrawLine(victimPos, new Vector3(victimPos.x + 1.0f, victimPos.y, victimPos.z), Color.red); Debug.DrawLine(predatorPos, new Vector3(predatorPos.x, predatorPos.y, predatorPos.z + 5.0f), Color.blue); Debug.DrawLine(predatorPos, new Vector3(predatorPos.x + 1.0f, predatorPos.y, predatorPos.z), Color.red); Vector3 dir = Vec3Mathf.GetReverseDir(victimPos, predatorPos, length); Debug.DrawLine(victimPos, dir, Color.cyan); Vector3 dirRand = Vec3Mathf.GetReverseDir(victimPos, predatorPos, length, alpha); Debug.DrawLine(victimPos, dirRand, Color.yellow); yield return(null); } }
public virtual void FindSaveZone(Vector3 predatorPos) { variantsZones.Clear(); finalZone = null; foreach (Transform zone in SaveZones) { if (Vector3.Angle(-Vec3Mathf.DirectionTo(transform.position, predatorPos), Vec3Mathf.DirectionTo(transform.position, zone.position)) < 130) { variantsZones.Add(zone); } } Transform[] variants = variantsZones.ToArray(); if (variants.Length > 1) { ChooseZone(variants); } else { ChooseZone(SaveZones); } }
void Update() { vec3Zero = transform.position; Debug.DrawLine(vec3Zero, Vec3Mathf.GetCircleSinPoint(vec3Zero, alpha, rad, modCY)); movableObject.position = Vector3.MoveTowards(movableObject.position, dest, 1.0f); timer += Time.deltaTime; alpha += 1.0f * Time.deltaTime * speed; if (timer > 0.1f) { timer = 0.0f; traectory.Add(Vec3Mathf.GetCircleSinPoint(vec3Zero, alpha, rad, modCY)); dest = Vec3Mathf.GetCircleSinPoint(vec3Zero, alpha, rad, modCY); } for (int i = 1; i < traectory.Count; i++) { Debug.DrawLine(traectory[i - 1], traectory[i]); } }
void FindMouse() { int mousesInDir = 0; foreach (Transform mouse in mouseTrans) { Vector3 dir = Vec3Mathf.DirectionTo(transform.position, mouse.position); if (Vector3.Angle(transform.forward, dir) < 20) { mousesInDir++; } } if (mousesInDir > 0) { s_source.volume = 1; } else { s_source.volume = 0.3f; } //s_source.Play(); }
protected override IEnumerator Secure() { while (fow.visibleTargets.Count < 1) { yield return(null); if (Vec3Mathf.DistanceTo(transform.position, ai.areaCenter.position) < 1.3f) { model.enabled = false; } } visibleTarget = fow.visibleTargets [0]; yield return(new WaitForSeconds(5)); if (fow.visibleTargets.Count > 0) { ChangeCondition(Condition.Alarm, "Secure", "Alarm"); } else { StartCoroutine("Secure"); } }
// Update is called once per frame void Update() { if (fow.isDanger && target3d != null) { image.enabled = true; } else { image.enabled = false; } if (target3d != null) { float targetAngle = Vec3Mathf.GetAngle1(player.position, target3d.position) + Camera.main.transform.rotation.eulerAngles.y; transform.localPosition = Vec3Mathf.GetCirclePointXZ(canvasCenter.localPosition, targetAngle, rad); float selfAngle = Vec3Mathf.GetAngleCanvas(transform.localPosition, canvasCenter.localPosition); transform.localRotation = Quaternion.Euler(0.0f, 0.0f, selfAngle); } //Debug.DrawLine(canvasCenter.position, new Vector3(canvasCenter.position.x, canvasCenter.position.y + 540.0f, canvasCenter.position.z)); //Debug.DrawLine(canvasCenter.position, transform.position); }
void Update() { timeBetSteps = freq / agent.velocity.magnitude; if (stepIndex == poolSize) { stepIndex = 0; } if (agent.velocity.magnitude > 0) { stepTimer += Time.deltaTime; if (stepTimer > timeBetSteps) { stepTimer = 0; Ray ray = new Ray(stepPos.position, -Vector3.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2f, groundMask)) { steps [stepIndex].position = hit.point + Vector3.up * 2.0f; steps[stepIndex].rotation = Vec3Mathf.GetDir(transform.position, steps[stepIndex].position); float corr = Random.Range(-0.3f, 0.3f); steps[stepIndex].position = new Vector3( steps[stepIndex].position.x + corr, steps[stepIndex].position.y, steps[stepIndex].position.z ); rotCalc.MakeCalculations(steps[stepIndex], steps[stepIndex]); rotCalc.MakeCalculationsZ(steps[stepIndex], steps[stepIndex]); place.Place(steps[stepIndex]); steps [stepIndex].gameObject.SetActive(true); stepIndex++; } } } }
IEnumerator FlyAroundPointSafety() { Vector3 startPos = transform.position; float condTime = 0.0f; float angle = Vec3Mathf.GetAngle(transform.position, agent.destination); //Debug.Log(angle); agent.SetDestination(destination = Vec3Mathf.GetCirclePoint(startPos, angle, rad)); while (true) { safetyWalkTime += 0.01f; condTime += 0.01f;//Time.deltaTime; if (agent.remainingDistance < remDist) { angle += anglePlus; destination = Vec3Mathf.GetCirclePoint(startPos, angle, rad); agent.SetDestination(destination); //Debug.Log("Добавляю угол:" + anglePlus); } if (condTime >= 5.0f) { ChangeCondition(Condition.Safety, "FlyAroundPointSafety", "Safety"); } if (fow.visibleTargets.Count > 0) { isEnemySpotted = true; visibleTarget = fow.visibleTargets[0]; ChangeCondition(Condition.Alarm, "FlyAroundPointSafety", "Alarm"); } //if(safetyWalkTime > 15.0f) //{ // ChangeCondition(Condition.Secure, "FlyAroundPointSafety", "GoBackToTheSpot"); //} Debug.DrawLine(startPos, agent.destination, Color.red); yield return(new WaitForSeconds(0.01f)); } }
protected override IEnumerator Alarm() { float time = 0; float escape_time = 0; //Debug.Log("overrided Alarm() started | this is inherited method from AnimalMotor"); agent.speed = runSpeed; float randomSec = Random.Range(0.2f, 0.3f); //agent.ResetPath(); agent.SetDestination(destination = Vec3Mathf.GetReverseDir(transform.position, visibleTarget.position, 20.0f)); while (true) { time += Time.deltaTime; escape_time += Time.deltaTime; if (time >= randomSec) { //Debug.Log("Задаем новою точку перемещения"); //agent.ResetPath(); agent.SetDestination(destination = Vec3Mathf.GetReverseDir(transform.position, visibleTarget.position, 20.0f, 15)); time = 0; } if (fow.visibleTargets.Count > 0 && escape_time > 1) { break; } if (fow.visibleTargets.Count < 1 && escape_time > 1) { ChangeCondition(Condition.Secure, "Alarm", "Secure"); } yield return(new WaitForSeconds(0.05f)); } escape_time = 0; //Debug.Log("changing condition to alarm"); visibleTarget = null; ChangeCondition(Condition.Safety, "Alarm", "Safety"); }
protected override IEnumerator Alarm() { float time = 0; float chaseTime = 0; //Debug.Log("overrided Alarm() started | this is inherited method from AnimalMotor"); agent.speed = runSpeed; float randomSec = Random.Range(0.5f, 0.6f); //agent.ResetPath(); agent.SetDestination(Vec3Mathf.GetReverseDir(transform.position, visibleTarget.position, 35)); while (true) { time += Time.deltaTime; chaseTime += Time.deltaTime; //Debug.Log(chaseTime); //Debug.Log(time); if (time >= randomSec) { float randomAngle = Random.Range(-fow.viewAngle / 2, fow.viewAngle / 2); //Debug.Log("Задаем новою точку перемещения"); //agent.ResetPath(); agent.SetDestination(Vec3Mathf.GetReverseDir(transform.position, visibleTarget.position, 15, randomAngle)); time = 0; //randomSec = Random.Range(0.3f, 0.6f); } if (fow.visibleTargets.Count == 0 && chaseTime > 1.5f) { break; } yield return(new WaitForSeconds(0.05f)); } //Debug.Log("changing condition to alarm"); visibleTarget = null; ChangeCondition(Condition.Secure, "Alarm", "Secure"); }
public void Run(Vector3 start, Vector3 target) { startPos = start; targPos = target; graphLength = (Vector3.Distance(startPos, targPos) / rad) - limit; //Debug.Log(graphLength); if (graphLength >= 1) { vec3points = new Vector3[(int)graphLength]; } else { vec3points = new Vector3[1]; } angle = Vec3Mathf.GetAngle(start, target); //Debug.Log(angle); //Debug.Log("start: "+start +"angle: "+ target); CalcGraph(); if (graphLength < 5) { rar = 1; } }
// методы траектории IEnumerator MakeDive() { agent.enabled = false; traectory.graphCorrection = 50.0f; traectory.CalcGraph(transform.position, visibleTarget.position); destination = traectory.GetNextPoint(); Debug.Log("Совершили атаку на игрока"); transform.rotation = Vec3Mathf.GetDirXY(transform.position, visibleTarget.position); while (Vector3.Distance(transform.position, visibleTarget.position) > 1.0f) { transform.rotation = Vec3Mathf.GetDirXY(transform.position, visibleTarget.position); transform.position = Vector3.MoveTowards(transform.position, visibleTarget.position, 1.0f); float dist = Vec3Mathf.DistanceTo(transform.position, visibleTarget.position); Debug.Log(dist); if (dist < attackDistance) { PlayerHealth playerHP = FindObjectOfType <PlayerHealth>(); if (playerHP != null) { playerHP.TakeDamage(70); } break; } yield return(new WaitForEndOfFrame()); } traectory.graphCorrection = 0.0f; traectory.CalcGraph(transform.position, destination = eaglePatrolPos); transform.rotation = Vec3Mathf.GetDirXY(transform.position, destination); while (Vector3.Distance(transform.position, destination) > 1.0f) { transform.position = Vector3.MoveTowards(transform.position, destination, 1.0f); yield return(new WaitForEndOfFrame()); } isEnemyInSight = false; ChangeCondition(Condition.Alarm, "MakeDive", "Alarm"); }
// Use this for initialization void Start() { traectory = new List <Vector3>(); traectory.Add(GetCircleSinPoint(alpha, rad, modCY)); dest = Vec3Mathf.GetCircleSinPoint(vec3Zero, alpha, rad, modCY); }
// Update is called once per frame void Update() { startRot.rotation = Vec3Mathf.GetDirXY(startRot.position, endRot.position); }