public void SailRotation() { float windangle = RaceSceneController.instance.windAngle; float windangleonboat = windangle - this.transform.localEulerAngles.z; if (windangleonboat < 0) { windangleonboat += 360; } windangleonboat = Mathf.RoundToInt(windangleonboat); if (windangleonboat >= 180) { //Bakboord float sailangle = MainGameController.Map(windangleonboat, 180, 360, 180, 260); Vector3 angles = new Vector3(0, 0, sailangle); _sailImage.transform.localEulerAngles = Vector3.Lerp(_sailImage.transform.localEulerAngles, angles, Time.deltaTime); } else { //Stuurboord float sailangle = MainGameController.Map(windangleonboat, 0, 180, 280, 360); Vector3 angles = new Vector3(0, 0, sailangle); _sailImage.transform.localEulerAngles = Vector3.Lerp(_sailImage.transform.localEulerAngles, angles, Time.deltaTime); } }
public void UpdatePlayerImage() { Vector2 pos = -_waypointPanel.transform.localPosition; pos.x = MainGameController.Map(pos.x, -8192, 8192, -250, 250); pos.y = MainGameController.Map(pos.y, -8192, 8192, -250, 250); _playerImage.transform.localPosition = pos; _playerImage.transform.localEulerAngles = _boat.transform.localEulerAngles + _boatImageOffset; }
public void UpdateOpponent() { for (int i = 0; i < _opponents.Count; i++) { GameObject opponent = _opponents[i]; Vector2 pos = opponent.transform.GetChild(0).localPosition; pos.x = MainGameController.Map(pos.x, -8192, 8192, -250, 250); pos.y = MainGameController.Map(pos.y, -8192, 8192, -250, 250); _opponentImages[i].transform.localPosition = pos; _opponentImages[i].transform.localEulerAngles = opponent.transform.GetChild(0).localEulerAngles + _boatImageOffset; } }
// Update is called once per frame void Update() { //if (Input.GetKeyDown(KeyCode.S)) //{ // now = now.Add(new TimeSpan(1, 0, 0)); //} if (DayNightAffected._sunrise != 0 && DayNightAffected._sunset != 0) { now = DateTime.Now; Int32 unixTimestamp = (Int32)(now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; float angle = MainGameController.Map(unixTimestamp, DayNightAffected._sunrise, DayNightAffected._sunset, 90, 270); this.transform.localEulerAngles = Vector3.Lerp(this.transform.localEulerAngles, new Vector3(0, 0, angle), Time.deltaTime); } }
public void DrawTrack(Track t) { foreach (Vector2 loc in t.GetWaypoints()) { GameObject buoy = GameObject.Instantiate(_buoyImage); buoy.transform.SetParent(_trackParent.transform); buoy.transform.localScale = Vector3.one; Vector2 pos = loc; pos.x = MainGameController.Map(pos.x, -8192, 8192, -250, 250); pos.y = MainGameController.Map(pos.y, -8192, 8192, -250, 250); buoy.transform.localPosition = pos; } }
void MoveBoat() { float myangle = GetAngleTwWind(); _upwindTarget = this.transform.position.y < _target.transform.position.y ? true : false; _upwindBoat = myangle > 90 && myangle < 270 ? false : true; float angleTwWind = GetAngleTwWind(); if (angleTwWind > 180) { angleTwWind = 360 - angleTwWind; } float windSpeed = RaceSceneController.instance.windSpeed; _speed = calculateForwardSpeed(angleTwWind, windSpeed); _speed = MainGameController.Map(_speed, calculateForwardSpeed(1, windSpeed), calculateForwardSpeed(130, windSpeed), _minVelocity, _maxVelocity); _velocity = this.transform.up * _speed; SailRotation(); }
public void BoatMovement() { float angleTwWind = GetAngleTwWind(); if (angleTwWind > 180) { angleTwWind = 360 - angleTwWind; } float windSpeed = RaceSceneController.instance.windSpeed; _speed = calculateForwardSpeed(angleTwWind, windSpeed); //float forwardForce = calculateForwardSpeed(angleTwWind, 10); //float reactiveForce = 0.5f * 1f * Mathf.Pow(forwardForce, 2) * 0.09f; //float acceleration = forwardForce - reactiveForce; //_speed += acceleration; if (_speed == float.NegativeInfinity) { _speed = calculateForwardSpeed(1, windSpeed); } if (_speed == float.PositiveInfinity) { _speed = calculateForwardSpeed(_bestWindAngle, windSpeed); } //Map speed _speed = MainGameController.Map(_speed, calculateForwardSpeed(1, windSpeed), calculateForwardSpeed(130, windSpeed), _minVelocity, _maxVelocity); if (_speed == float.NaN || float.IsNaN(_speed)) { _speed = calculateForwardSpeed(1, windSpeed); } float rotateSpeed = 5; float vmgRotateSpeed = 1; Vector3 relativePos = _target.transform.position - this.transform.position; //Angle between current position and the target position float angle = Vector2.Angle(this.transform.up, relativePos); //Map rotation speed for quicker rotation when angle towards target is greater _rotationSpeed = MainGameController.Map(angle, 0, 180, 1, 20); float myangle = GetAngleTwWind(); //Is the target upwind from current position _upwindTarget = this.transform.position.y < _target.transform.position.y ? true : false; //Is the boat currently sailing upwind _upwindBoat = myangle > 90 && myangle < 270 ? false : true; //If boat is sailing downwind if (!_upwindTarget) { //Change the rotation direction of the vmg calculations vmgRotateSpeed *= -1; } //If boat is sailing port tack if (myangle > 180) { //change rotation direction so upwind is still upwind rotateSpeed *= -1; } float vmg = (VelocityMadeGood(windSpeed, angleTwWind, angle, (angleTwWind < 90))); float vmgUp = (VelocityMadeGood(windSpeed, angleTwWind, angle - vmgRotateSpeed, (angleTwWind + vmgRotateSpeed < 90))); float vmgDown = (VelocityMadeGood(windSpeed, angleTwWind, angle + vmgRotateSpeed, (angleTwWind - vmgRotateSpeed < 90))); //Wind angle in relation with target angle. float twTargetWindangle = angleTwWind;// - angle; Vector3 other = _target.transform.position - this.transform.position; float angledir = Vector2.Dot(this.transform.right, other); float twTarget = 1; if (myangle > 180) { twTarget *= -1; } //left < 0 //right > 0 if ((angledir < 0)) { twTargetWindangle += angle * twTarget; } else { twTargetWindangle -= angle * twTarget; } if (twTargetWindangle < 0) { twTargetWindangle *= -1; } if (twTargetWindangle > 180) { twTargetWindangle = 360 - twTargetWindangle; } float vmgTowardsTarget = VelocityMadeGood(windSpeed, twTargetWindangle, 0, angleTwWind < 90); if (vmgUp == float.PositiveInfinity || vmgUp == float.NegativeInfinity) { vmgUp = float.MinValue; } if (vmgDown == float.PositiveInfinity || vmgUp == float.NegativeInfinity) { vmgDown = float.MinValue; } bool angleTwWindSmallerThenAngle = (angleTwWind < angle); if (myangle < 180) { angledir *= -1; } //If the vmg directly towards the target is better than the currently calculated vmg's then force to turn the direction of the target if ((vmgTowardsTarget > vmgUp || vmgTowardsTarget > vmgDown) && !angleTwWindSmallerThenAngle) { if (angledir < 0) { //left vmgUp = float.MaxValue; } else if (angledir > 0) { //right vmgDown = float.MaxValue; } else { //Infront vmg = float.MaxValue; } } if (!_tacking) { if (vmg < vmgUp && vmgUp > vmgDown)// && updiff > minimumDiff) { Quaternion rot = Quaternion.Lerp(this.transform.rotation, Quaternion.Euler(this.transform.eulerAngles - new Vector3(0, 0, rotateSpeed)), Time.deltaTime * _rotationSpeed); this.transform.rotation = rot; } else if (vmg < vmgDown && vmgDown > vmgUp)// && downdiff > minimumDiff) { Quaternion rot = Quaternion.Lerp(this.transform.rotation, Quaternion.Euler(this.transform.eulerAngles + new Vector3(0, 0, rotateSpeed)), Time.deltaTime * _rotationSpeed); this.transform.rotation = rot; } else { } } _velocity = this.transform.up * _speed; SailRotation(); }