private FlowDir SetDir(bool reverse, FlowDir fd, FlowDir newFd) { FlowDir re = fd; //反転してるとき if(reverse) { if (fd == FlowDir.DOWN && newFd == FlowDir.LEFT) re = fd; else re = newFd; if (isUp && isLeft) re = FlowDir.LEFT; if (isDown && isLeft) re = FlowDir.DOWN; if (isUp && isRight) re = FlowDir.UP; if (isDown && isRight) re = FlowDir.RIGHT; } //そのままの状態のとき else { if (fd == FlowDir.DOWN && newFd == FlowDir.RIGHT) re = fd; else if (fd == FlowDir.LEFT && newFd == FlowDir.DOWN) re = fd; else if(fd == FlowDir.RIGHT && newFd == FlowDir.UP) re = fd; else re = newFd; if (isUp && isRight) re = FlowDir.RIGHT; if (isDown && isRight) re = FlowDir.DOWN; if (isUp && isLeft) re = FlowDir.UP; if (isDown && isLeft) re = FlowDir.LEFT; } return re; }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Stage") || other.CompareTag("Goal")) { isCollisionStage = true; angle = other.transform.rotation.eulerAngles.z; collisionPosition = transform.position; colliderPosition = other.transform.position; } if (other.CompareTag("StageEdge")) { collisionPosition = transform.position; isCollisionStageEdge = true; colliderPosition = other.transform.position; } if (other.CompareTag("StageUp")) { collisionPosition = transform.position; angle = upAngle = other.transform.rotation.eulerAngles.z; isCollisionStageUp = true; colliderPosition = other.transform.position; } if (other.CompareTag("StageDown")) { collisionPosition = transform.position; angle = downAngle = other.transform.rotation.eulerAngles.z; isCollisionStageDown = true; colliderPosition = other.transform.position; } if (other.CompareTag("PoolWater")) { collisionPosition = other.GetComponent<PoolWater>().position; isCollisionPoolWater = true; colliderPosition = other.transform.position; } if (other.CompareTag("FlowUp") || other.CompareTag("FlowDown") || other.CompareTag("FlowRight") || other.CompareTag("FlowLeft")) { FlowingWater fw = other.GetComponent<FlowingWater>(); flowDir = SetDir(fw.reverse, flowDir, fw.dir); speed = fw.speed; } if(other.CompareTag("FlowStraight")) { StraightFlowingWater fw = other.GetComponent<StraightFlowingWater>(); flowDir = fw.dir; speed = fw.speed; straightAngle.Add(fw.angle); } if (other.CompareTag("Player")) { if (other.transform.position.y + 3.0f < transform.position.y) { isCollisionPlayerUp = true; player = other.gameObject; } } }
private void Start() { Init(); collisionPosition = new Vector3(0.0f, 0.0f, 0.0f); velocity = new Vector3(0.0f, 0.0f, 0.0f); dnChanger = GameObject.Find("DayNightChanger").GetComponent<DayNightChanger>(); gameCtrl = GameObject.Find("GameStateController").GetComponent<GameStateController>(); whc = GameObject.Find("WaterHeightController").GetComponent<WaterHeightController>(); poseCtrl = GameObject.Find("Pose").GetComponent<PoseController>(); oldIsDay = true; flowDir = FlowDir.NON; speed = 1.0f; straightAngle = new List<float>(); }
/// <summary> /// This is the main structure method, which much calculate the structure flow. /// It gets the upstream and downstream water level, and must calculate the three values: /// - <see cref="IStructure.Discharge"/> /// - <see cref="IStructure.dDischargedDownStreamWaterLevel"/> /// - <see cref="IStructure.dDischargedUpStreamWaterLevel"/>. /// <para> /// The derivatives with respect to downstream and upstream water level need not be calculated, /// nevertheless, the solution will be much more accurate and stable when included. /// </para> /// <para> /// Since this class is extending from the <see cref="Structure"/> class, /// we need to set the _q, _dqdhUpstream and _dqdhDownstream variables. /// </para> /// </summary> /// <param name="upStreamWaterLevel"> Water level in upstream direction (lower chainage - higher chainage if reach direction is reversed (Flow direction = negative)")</param> /// <param name="downStreamWaterLevel">Water level in downstream direction (higher chainage - lower chainage if reach direction is reversed (Flow direction = negative))</param> public override void SetWaterLevels(double upStreamWaterLevel, double downStreamWaterLevel) { // Determine flow direction FlowDir flowDir = upStreamWaterLevel >= downStreamWaterLevel ? FlowDir.PositiveFlow : FlowDir.NegativeFlow; // Set x and y such that x is the largest depth double x, y; if (flowDir == FlowDir.PositiveFlow) { x = upStreamWaterLevel - CrestLevel; y = downStreamWaterLevel - CrestLevel; } else { x = downStreamWaterLevel - CrestLevel; y = upStreamWaterLevel - CrestLevel; } if (x < 1e-15) { // Flow upstream water level below crest level // Set _q and derivatives to zero. _q = 0; _dqdhUpstream = 0; _dqdhDownstream = 0; } else if (x - y > Delhs) { // Difference between upstream and downstream water level is sufficiently big // Calculate structure flow HonmaWeirFlow(x, y); } else { // For water level differences less than delhs, use a linear variation in Q // between (x,y) = (x,x-delhs) and (x,x). This is to avoid stability problems // for small water level differences where dQdh goes to infinity. HonmaWeirFlow(x, x - Delhs); Linearisation(ref _q, ref _dqdhUpstream, ref _dqdhDownstream, Delhs, x - y); } // If the flow is negative, switch sign and derivatives if (flowDir == FlowDir.NegativeFlow) { SwitchFlowDirection(ref _q, ref _dqdhUpstream, ref _dqdhDownstream); } }
private void OnTriggerExit(Collider other) { if (other.CompareTag("Stage") || other.CompareTag("Goal")) { isCollisionStage = false; angle = 0; } if (other.CompareTag("StageEdge")) { isCollisionStageEdge = false; } if (other.CompareTag("StageUp")) { isCollisionStageUp = false; upAngle = 0; angle = 0; } if (other.CompareTag("StageDown")) { isCollisionStageDown = false; downAngle = 0; angle = 0; } if (other.CompareTag("PoolWater")) { isCollisionPoolWater = false; } if (other.CompareTag("FlowUp")) { FlowingWater fw = other.GetComponent<FlowingWater>(); if (fw.reverse) isDown = false; else isUp = false; } if (other.CompareTag("FlowDown")) { FlowingWater fw = other.GetComponent<FlowingWater>(); if (fw.reverse) isUp = false; else isDown = false; } if (other.CompareTag("FlowLeft")) { FlowingWater fw = other.GetComponent<FlowingWater>(); if (fw.reverse) isRight = false; else isLeft = false; } if (other.CompareTag("FlowRight")) { FlowingWater fw = other.GetComponent<FlowingWater>(); if (fw.reverse) isLeft = false; else isRight = false; } if(other.CompareTag("FlowStraight")) { straightAngle.RemoveAt(0); } if (other.CompareTag("Player")) { if (other.transform.position.y < transform.position.y) { isCollisionPlayerUp = false; player = null; } } if (!isUp && !isDown && !isLeft && !isRight && straightAngle.Count == 0) flowDir = FlowDir.NON; }
public void ResetDir() { flowDir = FlowDir.NON; }