// Update is called once per frame void Update() { path.draw(); if (reversePath && isAtEndOfPath()) { path.reversePath(); } Vector3 accel = followPath.getSteering(path, pathLoop); steeringBasics.steer(accel); steeringBasics.lookWhereYoureGoing(); }
private void placeBaseAndHero() { Room r = rooms [0]; //Place player objects Vector3 pos = placeBase(r.centerX - 1, r.centerY, TeamMember.TEAM_1); pos.x += 3 * tileSize; pos.y += 1 * tileSize; Hero startHero = placeHero(pos, TeamMember.TEAM_1); gm.selectHero(startHero); for (int i = 1; i < 5; i++) { placeHero(pos + Vector3.down * tileSize * i, TeamMember.TEAM_1); placeHero(pos + ((-0.5f + i) * Vector3.down * tileSize) + (Vector3.right * tileSize), TeamMember.TEAM_1); } //Place enemy objects placeBase(map.width - 1 - (r.centerX - 1), r.centerY, TeamMember.TEAM_2); pos.x = (map.width) * tileSize - pos.x; Hero enemyHero = placeHero(pos, TeamMember.TEAM_2); Vector3[] patrolNodes = new Vector3[2]; patrolNodes [0] = new Vector3(pos.x, pos.y + 3 * tileSize, pos.z); patrolNodes [1] = new Vector3(pos.x + 6 * tileSize, pos.y + 3 * tileSize, pos.z); // patrolNodes [2] = new Vector3 (pos.x + 6 * tileSize, pos.y - 3 * tileSize, pos.z); // patrolNodes [3] = new Vector3 (pos.x, pos.y - 3 * tileSize, pos.z); LinePath patrolPath = new LinePath(patrolNodes); patrolPath.draw(); enemyHero.patrolPath = patrolPath; HealthBar hb = enemyHero.GetComponent <HealthBar> (); hb.barMax = 10000f; hb.barProgress = 10000f; enemyHero = placeHero(pos + Vector3.down * tileSize, TeamMember.TEAM_2); hb = enemyHero.GetComponent <HealthBar> (); hb.barMax = 10000f; hb.barProgress = 10000f; }
void Update() { path.draw(); // 执行原路返回的逻辑 if (reversePath && isAtEndOfPath()) { path.reversePath(); } // 计算线性加速度 Vector3 accel = followPath.getSteering(path, pathLoop); // 设置刚体速度 steeringBasics.Steer(accel); // 朝向 steeringBasics.LookWhereYoureGoing(); }
void FixedUpdate() { if (followPath.isAtEndOfPath(path)) { path.reversePath(); } Vector3 accel = wallAvoidance.getSteering(); if (accel.magnitude < 0.005f) { accel = followPath.getSteering(path); } steeringBasics.steer(accel); steeringBasics.lookWhereYoureGoing(); path.draw(); }
// Update is called once per frame void Update() { path.draw(); if (isAtEndOfPath()) { path.reversePath(); } Vector2 accel = colAvoid.getSteering(colAvoidSensor.targets); if (accel.magnitude < 0.005f) { accel = followPath.getSteering(path); } steeringBasics.steer(accel); steeringBasics.lookWhereYoureGoing(); }
private void Update() { // 到达终点了, 原路返回 if (IsAtEndOfPath()) { path.reversePath(); } // 得到加速度 (要躲避墙) Vector3 accel = wallAvoidance2.GetSteering(); // 沿着路径走了 (约定没有碰撞时, 加速度为0 了) if (accel.magnitude < 0.005f) { accel = followPath.getSteering(path); } // 设置刚体 和 朝向 steeringBasics2.Steer(accel); steeringBasics2.LookWhereYoureGoing(); // 调试 path.draw(); }
void moveAlongPath() { rb.constraints = RigidbodyConstraints2D.FreezeRotation; updatePathParam(); // Clean up any destroyed targets collAvoidSensor.targets.RemoveWhere(t => t == null); Vector2 followAccel = followPath.getSteering(currentPath, isLoopingPath()); Transform ignoreUnit = (target != null) ? target.transform : null; Vector2 collAvoidAccel = steeringUtils.collisionAvoidance(collAvoidSensor.targets, ignoreUnit); steeringUtils.steer(followAccel + 2 * collAvoidAccel); steeringUtils.lookWhereYoureGoing(); // Debug drawing Vector3 foo = collAvoidAccel.normalized * 3; Debug.DrawLine(transform.position, transform.position + foo, Color.cyan); currentPath.draw(); }
void Update() { // 调试 path.draw(); // 是否原路返回 if (isAtEndOfPath()) { path.reversePath(); } // 躲避 加速度 Vector3 accel = colAvoid.GetSteering(colAvoidSensor.targets); // 不需要躲避 就沿着路径走 if (accel.magnitude < 0.005f) { accel = followPath.getSteering(path); } // 设置刚体速度 和 朝向 steeringBasics.Steer(accel); steeringBasics.LookWhereYoureGoing(); }