public void Update(float aDeltaTime, float aTimeScale) { _delta = _particle.CurrentLifeTime / _particle.LifeTime; _dx = AntMath.Lerp(_startScale.x, _endScale.x, _curveX.Evaluate(_delta)); _dy = AntMath.Lerp(_startScale.y, _endScale.y, _curveY.Evaluate(_delta)); if (_useChild) { _childTransform.localScale = new Vector3( _dx, (_proportional) ? _dx : _dy, 1.0f ); } else { _transform.localScale = new Vector3( _dx, (_proportional) ? _dx : _dy, 1.0f ); } }
public int GetNearEdge(Vector2 aPosition) { float dist; float minValue = float.MaxValue; int minIndex = -1; Vector2 edgePos = Vector2.zero; Vector2 a, b; for (int i = 0, n = edges.Count; i < n; i++) { if (!edges[i].HasNeigbors) { a = vertices[edges[i].a]; b = vertices[edges[i].b]; edgePos.x = (a.x + b.x) * 0.5f; edgePos.y = (a.y + b.y) * 0.5f; dist = AntMath.Distance(aPosition, edgePos); if (dist < minValue) { minValue = dist; minIndex = i; } } } return(minIndex); }
public void DropItem() { GameObject go = null; ItemKind kind = (randomDrop) ? _rndList[AntMath.RandomRangeInt(0, _rndList.Length - 1)] : dropKind; switch (kind) { case ItemKind.Bomb: go = GameObject.Instantiate((GameObject)_gameCore.bombItemPrefab); break; case ItemKind.Gun: go = GameObject.Instantiate((GameObject)_gameCore.gunItemPrefab); break; case ItemKind.Ammo: go = GameObject.Instantiate((GameObject)_gameCore.ammoItemPrefab); break; case ItemKind.Heal: go = GameObject.Instantiate((GameObject)_gameCore.healItemPrefab); break; } if (go != null) { go.GetComponent <Transform>().position = _t.position; AntEngine.Current.AddEntity(go.GetComponent <AntEntity>()); } }
public void Play() { _isPlaying = true; var pos = new Vector3( _transform.position.x + _positionOffset.x, _transform.position.y + _positionOffset.y, _transform.position.z ); _effect = AntEffectEngine.GetEffect(_settings.prefab.name, pos); _effect.EventComplete += EffectCompleteHandler; _effect.Angle = (_settings.isInheritAngle) ? _angle + _transform.rotation.eulerAngles.z : _angle; if (_settings.customDelay) { _effect.startDelay = _settings.delay + AntMath.RandomRangeFloat(_settings.rndToDelay); } if (_settings.customLifeTime) { _effect.isLooping = false; _effect.lifeTime = _settings.lifeTime + AntMath.RandomRangeFloat(_settings.rndToLifeTime); } _effect.Reset(); _effect.Play(); }
private void DropItem(ItemKind aKind, Vector3 aPosition) { GameObject go = null; switch (aKind) { case ItemKind.Bomb: go = GameObject.Instantiate((GameObject)_gameCore.bombItemPrefab); break; case ItemKind.Gun: go = GameObject.Instantiate((GameObject)_gameCore.gunItemPrefab); break; case ItemKind.Ammo: go = GameObject.Instantiate((GameObject)_gameCore.ammoItemPrefab); break; case ItemKind.Heal: go = GameObject.Instantiate((GameObject)_gameCore.healItemPrefab); break; } if (go != null) { float angle = AntMath.DegToRad(AntMath.RandomRangeFloat(-180, 180)); Vector2 force = new Vector2(); force.x = 0.5f * Mathf.Cos(angle); force.y = 0.5f * Mathf.Sin(angle); go.GetComponent <Transform>().position = aPosition; go.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse); Engine.AddEntity(go.GetComponent <AntEntity>()); } }
public override void Enter() { _targetAngle = AntMath.AngleDeg(_control.Position, _blackboard.EnemyTank.Position); // Calc spawn point for the bullet. // This point should be outside the tank body, // otherwise this bullet will damage our self. var ang = _control.Tower.Angle * AntMath.RADIANS; var p = _control.Position; p.x += 0.45f * Mathf.Cos(ang); p.y += 0.45f * Mathf.Sin(ang); // Spawn and execute the bullet. var bullet = Game.Instance.SpawnBullet(p, _control.transform.parent); Quaternion q = Quaternion.AngleAxis(_control.Tower.Angle, Vector3.forward); bullet.transform.rotation = q; bullet.Execute(_control.Tower.Angle); _control.Tower.TakeAmmo(1); _delay = 0.75f; _control.Tower.ShotEffect(); }
public void Update(float aDeltaTime, float aTimeScale) { _delta = _particle.CurrentLifeTime / _particle.LifeTime; if (Preset.colour.animateColor) { _curColor = (_useChild) ? _childSprite.color : _sprite.color; _curColor.r = AntMath.Lerp(_curColor.r, _endColor.r, _curve.Evaluate(_delta)); _curColor.g = AntMath.Lerp(_curColor.g, _endColor.g, _curve.Evaluate(_delta)); _curColor.b = AntMath.Lerp(_curColor.b, _endColor.b, _curve.Evaluate(_delta)); _curColor.a = AntMath.Lerp(_curColor.a, _endColor.a, _curve.Evaluate(_delta)); if (_useChild) { _childSprite.color = _curColor; } else { _sprite.color = _curColor; } } else if (_gradientColor) { if (_useChild) { _childSprite.color = _gradient.Evaluate(_delta); } else { _sprite.color = _gradient.Evaluate(_delta); } } }
/// <summary> /// Starts playing current animation from the random frame. /// </summary> public void PlayRandomFrame() { if (_isAnimInitialized) { GotoAndPlay(AntMath.RandomRangeInt(1, TotalFrames)); } }
public void Reset(AntEmitter aEmitter) { _curColor = Preset.colour.startColor; _endColor = Preset.colour.endColor; _gradient = Preset.colour.gradient; _curve = Preset.colour.curveColor; _useChild = Preset.colour.useChildSprite; _gradientColor = Preset.colour.gradientColor; IsActive = (Preset.colour.animateColor || Preset.colour.gradientColor); if (Preset.colour.effectLifeTime) { _delta = _particle.Effect.Duration / _particle.Effect.TotalDuration; _delta = AntMath.TrimToRange(_delta, 0.0f, 1.0f); _curColor.r = AntMath.Lerp(_curColor.r, _endColor.r, _curve.Evaluate(_delta)); _curColor.g = AntMath.Lerp(_curColor.g, _endColor.g, _curve.Evaluate(_delta)); _curColor.b = AntMath.Lerp(_curColor.b, _endColor.b, _curve.Evaluate(_delta)); _curColor.a = AntMath.Lerp(_curColor.a, _endColor.a, _curve.Evaluate(_delta)); } if (_useChild) { _childSprite.color = _curColor; } else { _sprite.color = _curColor; } }
public override void Enter() { // Search base on the map. var go = GameObject.Find("Base"); if (go != null) { // This action called if we don't see the base. // So try to find base select random position around // the base until we will found it. var basePos = go.transform.position; _targetPos = new Vector3( basePos.x + AntMath.RandomRangeFloat(-2.0f, 2.0f), basePos.y + AntMath.RandomRangeFloat(-2.0f, 2.0f), 0.0f ); // Calc target angle. _targetAngle = AntMath.AngleDeg(_t.position, _targetPos); _t.rotation = Quaternion.Euler(_t.rotation.x, _t.rotation.y, _targetAngle); _targetAngle *= Mathf.Deg2Rad; } else { Debug.Log("Base not found!"); Finish(); } }
protected bool OnMove() { if (Config.Instance.showCurrentWay) { DrawWay(); } // Достигли текущей точки! if (AntMath.Distance((Vector2)_control.Position, _nextPoint) < WayMap.Current.approachRadius) { NextPoint(); } // Рулежка. UpdateAngle(); if (!AntMath.Equal(AntMath.Angle(_control.Angle), AntMath.Angle(_targetAngle), 1.0f)) { float curAng = AntMath.Angle(_control.Angle); float tarAng = AntMath.Angle(_targetAngle); if (Mathf.Abs(curAng - tarAng) > 180.0f) { if (curAng > tarAng) { tarAng += 360.0f; } else { tarAng -= 360.0f; } } if (curAng < tarAng) { _control.isLeft = true; _control.isRight = false; } else if (curAng > tarAng) { _control.isLeft = false; _control.isRight = true; } } else { _control.isLeft = false; _control.isRight = false; // Газ. if (!_isWayFinished) { _control.isForward = true; } else { _control.isForward = false; } } return(_isWayFinished); }
public void Update(float aDeltaTime, float aTimeScale) { if (_movement.gravity) { _velocity.x += _movement.gravityFactor.x * aDeltaTime * aTimeScale; _velocity.y += _movement.gravityFactor.y * aDeltaTime * aTimeScale; if (_movement.rotate) { Angle = AntMath.AngleDeg(_velocity); } } else { _delta = _particle.CurrentLifeTime / _particle.LifeTime; _angle = Angle * AntMath.RADIANS; _velocity.x = _speed * Mathf.Cos(_angle); _velocity.y = _speed * Mathf.Sin(_angle); if (_movement.animateSpeed) { _speed = AntMath.Lerp(_startSpeed, _endSpeed, _movement.speedCurve.Evaluate(_delta)); } else { _speed += _movement.accel * aDeltaTime * aTimeScale; _speed *= _movement.drag; } } _position = _transform.position; _position.x += _velocity.x * aDeltaTime * aTimeScale; _position.y += _velocity.y * aDeltaTime * aTimeScale; _transform.position = _position; }
public override void Execute(float aDeltaTime, float aTimeScale) { // Aim on the target. if (!AntMath.Equal(AntMath.Angle(_control.towerRef.Angle), AntMath.Angle(_targetAngle), 1.0f)) { float curAng = AntMath.Angle(_control.towerRef.Angle); float tarAng = AntMath.Angle(_targetAngle); if (Mathf.Abs(curAng - tarAng) > 180.0f) { if (curAng > tarAng) { tarAng += 360.0f; } else { tarAng -= 360.0f; } } if (curAng < tarAng) { _control.RotateTower(1.0f, aDeltaTime); } else if (curAng > tarAng) { _control.RotateTower(-1.0f, aDeltaTime); } } else { Finish(); } }
/// <summary> /// Returns random point on the map. Useful if we don’t know /// where to send the tank, send it to a random point. /// </summary> /// <returns>Random point on the map.</returns> public Vector2 GetRandomPoint() { // Select random node in the NavMesh for random movement. int index = AntMath.RandomRangeInt(0, Game.NavMesh.nodes.Count - 1); // Get the center of node as our target. return(Game.NavMesh.GetNodeCenter(index)); }
private void UpdateAngle(bool aForce = false) { _updateAngleInterval -= Time.deltaTime; if (_updateAngleInterval < 0.0f || aForce) { _updateAngleInterval = 0.2f; _targetAngle = AntMath.AngleDeg((Vector2)_control.Position, _nextPoint); } }
public override void Start() { // Считываем из памяти информацию о положении врага. if (_blackboard["EnemyVisible"].AsBool) { _targetAngle = AntMath.AngleDeg((Vector2)_control.Position, _blackboard["EnemyVisible_Pos"].AsVector2); } }
public Vector2 GetOutputPoint(Vector2 aToPosition) { var pos = Position; float ang = AntMath.AngleDeg(pos, aToPosition); return(new Vector2( pos.x + 10.0f * Mathf.Cos((ang + 90.0f) * Mathf.Deg2Rad), pos.y + 10.0f * Mathf.Sin((ang + 90.0f) * Mathf.Deg2Rad) )); }
public bool NewParticleIsReady() { if (_spawnInterval <= 0.0f) { _spawnInterval = _preset.spawnInterval + AntMath.RandomRangeFloat(_preset.rndToSpawnInterval); return(true); } return(false); }
/// <summary> /// Gets random value from the Array. /// </summary> /// <param name="aSource">Array</param> /// <typeparam name="T">Type of Array.</typeparam> /// <returns>Random value of the Array.</returns> public static T GetRandom <T>(ref T[] aSource) { T result = default(T); if (aSource.Length > 0) { result = aSource[AntMath.RandomRangeInt(0, aSource.Length - 1)]; } return(result); }
private int FindVertex(Vector2 aPoint) { for (int i = 0, n = _self.vertices.Count; i < n; i++) { if (AntMath.Equal(_self.vertices[i], aPoint)) { return(i); } } return(-1); }
public void Reset(AntEmitter aEmitter) { IsActive = true; _preset = Preset.trail; _startTime = _preset.startTime + AntMath.RandomRangeFloat(_preset.rndToStartTime); _trail.widthMultiplier = _preset.startWidth + AntMath.RandomRangeFloat(_preset.rndToStartWidth); _trail.widthCurve = _preset.widthCurve; _trail.colorGradient = _preset.gradient; _trail.Clear(); _needToInit = true; }
public void Reset(AntEmitter aEmitter) { _duration = Preset.lifeTime.duration; _duration += AntMath.RandomRangeFloat(Preset.lifeTime.rndToDuration); if (_duration <= 0.0f) { _duration = 0.1f; } _particle.LifeTime = _duration; IsActive = true; }
public void Reset(AntEmitter aEmitter) { var center = _transform.position; var spawn = Preset.position; center.x = spawn.position.x + AntMath.RandomRangeFloat(spawn.rndToPositionX); center.y = spawn.position.y + AntMath.RandomRangeFloat(spawn.rndToPositionY); float lowerAngle = spawn.initialAngle + spawn.lowerAngle; float upperAngle = spawn.initialAngle + spawn.upperAngle; if (spawn.inheritRotation) { center = AntMath.RotatePointDeg(center, Vector2.zero, _particle.Effect.Angle); lowerAngle += _particle.Effect.Angle; upperAngle += _particle.Effect.Angle; } center.x += _particle.Effect.Position.x; center.y += _particle.Effect.Position.y; var pos = Vector2.zero; float curAngle; float dist = spawn.distance + AntMath.RandomRangeFloat(spawn.rndToDistance); if (spawn.strongOrder && spawn.countParticles > 0) { aEmitter.SpawnCount++; float step = Mathf.DeltaAngle(lowerAngle, upperAngle) / (spawn.countParticles - 1); curAngle = (lowerAngle + (step * aEmitter.SpawnCount)) * AntMath.RADIANS; pos.x = center.x + dist * Mathf.Cos(curAngle); pos.y = center.y + dist * Mathf.Sin(curAngle); if (aEmitter.SpawnCount >= spawn.countParticles) { aEmitter.SpawnCount = 0; } } else { curAngle = AntMath.RandomRangeFloat(lowerAngle, upperAngle) * AntMath.RADIANS; pos.x = center.x + dist * Mathf.Cos(curAngle); pos.y = center.y + dist * Mathf.Sin(curAngle); } if (spawn.rotate) { Angle = curAngle * AntMath.DEGREES; } _transform.position = pos; IsActive = false; // Выкл. обработку компонента. }
public int FindEdge(Vector2 aA, Vector2 aB) { for (int i = 0, n = _self.edges.Count; i < n; i++) { if (AntMath.Equal(_self.vertices[_self.edges[i].a], aA) && AntMath.Equal(_self.vertices[_self.edges[i].b], aB)) { return(i); } } return(-1); }
public override void Drag(Vector2 aDelta) { var oldPos = rect.position; base.Drag(aDelta); if (!AntMath.Equal(oldPos.x, rect.position.x) || !AntMath.Equal(oldPos.y, rect.position.y)) { _action.position = rect.position; EditorUtility.SetDirty(_scenario); } }
/// <summary> /// Pops random value from the array. /// </summary> /// <param name="aSource">Array.</param> /// <typeparam name="T">Type of Array.</typeparam> /// <returns>Random value of the Array.</returns> public static T PopRandom <T>(ref T[] aSource) { T result = default(T); if (aSource.Length > 0) { int i = AntMath.RandomRangeInt(0, aSource.Length - 1); result = aSource[i]; RemoveAt <T>(ref aSource, i); } return(result); }
private void AddPointToList(ref List <Vector2> aList, Vector2 aPoint) { for (int i = 0, n = aList.Count; i < n; i++) { if (AntMath.Equal(aList[i], aPoint)) { // This point already exists in the list, skip. return; } } aList.Add(aPoint); }
public void Reset(AntEmitter aEmitter) { IsActive = true; _movement = Preset.movement; _speed = _movement.speed + AntMath.RandomRangeFloat(_movement.rndToSpeed); _startSpeed = _speed; _endSpeed = _movement.endSpeed; _angle = Angle * AntMath.RADIANS; _velocity.x = _speed * Mathf.Cos(_angle); _velocity.y = _speed * Mathf.Sin(_angle); }
public void Steering(float aDir, float aDeltaTime) { float angle = _t.rotation.eulerAngles.z + steering * aDir * 0.6f; _body.rotation = AntMath.LerpAngle(_body.rotation, angle, aDeltaTime); /* * // Старый код вращения без физ тела. * float angle = _t.rotation.eulerAngles.z + steering * aDir; * Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward); * _t.rotation = Quaternion.Slerp(_t.rotation, q, aDeltaTime); * //*/ }
public Vector2 GetInputPoint(AntAIBaseNode aFromNode) { var pos = Position; pos.x += rect.width * 0.5f; pos.y += rect.height * 0.5f; float ang = AntMath.AngleDeg(pos, aFromNode.Position); return(new Vector2( pos.x - 10.0f * Mathf.Cos((ang + 90.0f) * Mathf.Deg2Rad), pos.y - 10.0f * Mathf.Sin((ang + 90.0f) * Mathf.Deg2Rad) )); }