protected override void Initialize() { _spriteBatch = new SpriteBatch(GraphicsDevice); var random = new Random((int)DateTime.Now.Ticks); _steeringTarget = new SteeringTarget(Vector2.Zero); _seekBehaviour = new SeekBehaviour(_steeringTarget); _fleeBehaviour = new FleeBehaviour(_steeringTarget); _currentSteeringBehaviour = _seekBehaviour; for (var i = 0; i < 3000; i++) { var entity = new Entity(this, _spriteBatch, new Vehicle { Position = new Vector2(random.Next(GraphicsDevice.Viewport.Width), random.Next(GraphicsDevice.Viewport.Height)), // Todo if you like: // Tweak these values to see how they affect the steering behaviours. MaxSpeed = 500, MaxForce = 350, Mass = 1f }); entity.SetSteeringBehaviour(_seekBehaviour); Components.Add(entity); } base.Initialize(); }
public FlyStraightBehaviour( SteeringManager manager ) : base(manager) { this.tag = "FlyStraight"; this.steeringWeight = 1.0f; seek = new SeekBehaviour (manager); }
void MoveToTarget() { Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); var targetlist = _trainData.ListTurret; int targetSize = targetlist.Length; int randomtarget = Random.Range(0, targetSize); targetPos = targetlist[randomtarget].gameObject.transform.position; Vector2 destination = new Vector2(targetPos.x, transform.position.y); _acceleration = BehaviourUpdate.BehaviourUpdated(SeekBehaviour.SeekMove(transform, destination, enemyData.MaxSpeed), enemyData.SeekWeight); _velocity += _acceleration * Time.deltaTime; float dis = float.MinValue; if (Mathf.Abs(transform.position.x - destination.x) < 0.1f) { mCurrentState = State.Charging; _nextAttackTime = Time.time + enemyData.AttackDelay + Random.Range(-enemyData.AttackDelay * 0.1f, enemyData.AttackDelay * 0.1f); } else { transform.position += _velocity * Time.deltaTime; } }
private Vector3 GetPursuitDirection(TestingSteering PlayerSteering, TestingSteering PursuitSteering) { Vector3 distance = PursuitSteering.CurrentPosition - PlayerSteering.CurrentPosition; float futureTime = distance.magnitude / PlayerSteering.MoveMaxSpeed; Vector3 futurePosition = PursuitSteering.CurrentPosition + PursuitSteering.CurrentVelocity * futureTime; return(SeekBehaviour.GetDirectionVector(PlayerSteering.CurrentPosition, futurePosition)); }
// Use this for initialization void Start() { timer = transitionTime; agent = GetComponent <NavMeshAgent>(); wander = GetComponent <Wander>(); seek = GetComponent <SeekBehaviour>(); flee = GetComponent <RandFlee>(); }
// Use this for initialization void Start () { stamina = 100; setElementType(); seekBehaviour = this.GetComponentInParent<SeekBehaviour>(); spellcaster = this.GetComponentInParent<Spellcaster>(); }
// Use this for initialization void Start() { restingTimer = restingTime; timer = transitionTimer; agent = GetComponent <NavMeshAgent>(); wander = GetComponent <WanderBehaviour>(); seek = GetComponent <SeekBehaviour>(); flee = GetComponent <Flee>(); }
public static Vector3 GetDirectionVector(TestingSteering playerSteering, TestingSteering leaderSteering) { Vector3 followPosition = GetFollowPosition(leaderSteering); Vector3 force = SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, followPosition); //force += Seperation(playerSteering); return(force); }
void SetLocationTarget(Vector3 position) { var agent = gameObject.GetComponent <AgentManager>(); agent.target.SetLocationTarget(position); MovementBehaviour behaviour = new SeekBehaviour(agent.target.location, true); agent.mover.AddBehaviour(behaviour); }
public AttackState(Transform gunTipPosition, Vector3 velocity, GameObject laserPrefab, Guid npcId) { this.gunTipPosition = gunTipPosition; this.velocity = velocity; this.laserPrefab = laserPrefab; this.id = npcId; seekBehaviour = new SeekBehaviour(); stateID = StateID.EnemyAttackStateID; }
private Vector3 GetFollowDirection(TestingSteering playerSteering, TestingSteering leaderSteering) { Vector3 tv = leaderSteering.CurrentVelocity * -1; tv = tv.normalized * _followDistance; Vector3 followPosition = leaderSteering.CurrentPosition + tv; Vector3 force = SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, followPosition); //force += Seperation(playerSteering); return(force); }
public BankHardRightBehaviour(SteeringManager manager) : base(manager) { this.tag = "BankHardRight"; this.radius = 400; this.dist = 600; this.pointOnSphere = Vector3.zero; this.sphere = new GameObject(); this.sphere.name = "BankHardRight"; seek = new SeekBehaviour(manager); }
public BankHardRightBehaviour( SteeringManager manager ) : base(manager) { this.tag = "BankHardRight"; this.radius = 400; this.dist = 600; this.pointOnSphere = Vector3.zero; this.sphere = new GameObject (); this.sphere.name = "BankHardRight"; seek = new SeekBehaviour (manager); }
public static Vector2 WanderMove(Transform agent, float mWanderRadius, float mWanderDistance, float mWanderJitter, float speed) { Vector2 mWanderPoint = Vector2.zero; mWanderPoint = mWanderPoint + Random.insideUnitCircle * mWanderJitter; mWanderPoint = mWanderPoint.normalized * mWanderRadius; //wanderPoint.y += wanderDistance; var wanderTarget = mWanderPoint + new Vector2(0.0f, mWanderDistance); var localToWorld = agent.transform.localToWorldMatrix; Vector2 destination = localToWorld.MultiplyVector((Vector3)wanderTarget); mWanderPoint = SeekBehaviour.SeekMove(agent, destination, speed); //mRenderPoint = destination; return(mWanderPoint); }
void Start() { if (backpack == null) { backpack = gameObject.AddComponent <BackpackComponent>( ) as BackpackComponent; } if (backpack.tool == null) { GameObject tool = Instantiate(toolPrefab, transform.position, transform.rotation) as GameObject; backpack.tool = tool; tool.transform.parent = transform; // attach the tool } seek = GetComponent <SeekBehaviour>(); }
public override TaskState Run() { SeekBehaviour seekBe = myAgent.GetComponent <SeekBehaviour>(); FleeBehaviour fleeBe = myAgent.GetComponent <FleeBehaviour>(); myAgent.maximumLinearVelocity = 1; Transform baseTransform = FindObjectOfType <Base>().transform; seekBe.weight = 0; fleeBe.weight = 1; fleeBe.targetTransform = baseTransform; return(TaskState.SUCCESS); }
public AvoidLockOnRightLeftBehaviour(SteeringManager manager) : base(manager) { this.tag = "AvoidLockOnRightLeft"; this.left = false; this.timeMax = 4.0f; this.radius = 200; this.dist = 400; this.pointOnSphere = Vector3.zero; this.sphere = new GameObject(); this.sphere.name = "AvoidLockOnSphere"; seek = new SeekBehaviour(manager); }
public FindFoodState(EntityStateMachine ownerFiniteStateMachine) : base(ownerFiniteStateMachine) { SeekBehaviour seekBehaviour = new SeekBehaviour(OwnerEntity.SeekTarget, OwnerEntity); wanderBehaviour = new WanderBehaviour(OwnerEntity); steeringBehaviours.Add(seekBehaviour); steeringBehaviours.Add(new DistancingBehaviour(OwnerEntity)); steeringBehaviours.Add(new ObstacleAvoidance(OwnerEntity)); Name = "FindFood"; // If the entity doesn't have a target for some reason, try to find one if (OwnerEntity.SeekTarget == null) { // try to find new target seekBehaviour.NewTarget(OwnerEntity.SeekTarget); // If it's still Null, no targets exist } }
public static Vector3 GetFormationDirection(TestingSteering playerSteering, TestingSteering leaderSteering, Vector3 positionOffset) { Vector3 leadRot = leaderSteering.transform.rotation.eulerAngles; float rot = leadRot.y * Mathf.Deg2Rad; float cs = Mathf.Cos(rot); float sn = Mathf.Sin(rot); float newX = ((cs * positionOffset.x) - (sn * positionOffset.x)); float newZ = ((sn * positionOffset.z) + (cs * positionOffset.z)); Vector3 tmpPos = new Vector3(newX, 0, newZ); tmpPos += leaderSteering.CurrentPosition; //Vector3 tmpPos = leaderSteering.CurrentPosition + positionOffset; return(SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, tmpPos)); }
public Hero(EntityManager entityManager, Vector2 position) : base(entityManager, position) { Mass = 1.0F; MaxSpeed = 80.0F; SteeringBehaviour = new SeekBehaviour(this, position); // Set animation frames animationFrames = new Rectangle[] { new Rectangle(24, 24, 24, 24), // North new Rectangle(48, 24, 24, 24), // North East new Rectangle(24, 48, 24, 24), // East new Rectangle(0, 24, 24, 24), // South East new Rectangle(0, 0, 24, 24), // South new Rectangle(24, 0, 24, 24), // South West new Rectangle(0, 48, 24, 24), // West new Rectangle(48, 0, 24, 24) // North West }; }
public override void OnStateUpdate(GameTime gameTime) { // If the seekTarget is null, there are no valid targets. In that case, // default back to wandering // SeekTarget automatically tries to get a new target in the getter if (OwnerEntity.SeekTarget == null && !isWandering) { steeringBehaviours.Add(wanderBehaviour); isWandering = true; } else { // If it found a target, no longer wander steeringBehaviours.Remove(wanderBehaviour); isWandering = false; SeekBehaviour seekbehaviour = (SeekBehaviour)steeringBehaviours[0]; seekbehaviour.NewTarget(OwnerEntity.SeekTarget); } base.OnStateUpdate(gameTime); }
public override TaskState Run() { SeekBehaviour seekBe = m_Agent.GetComponent <SeekBehaviour>(); FleeBehaviour fleeBe = m_Agent.GetComponent <FleeBehaviour>(); m_Agent.maximumLinearVelocity = 0f; var allAgents = FindObjectsOfType <Agent>(); if (btdm.currentEnemy != null) { seekBe.weight = 1; fleeBe.weight = 0; seekBe.targetTransform = btdm.currentEnemy.transform; m_Agent.GetComponent <ShootAction>().Shoot(); return(TaskState.SUCCESS); } return(TaskState.FAILURE); }
public static Vector3 GetDirectionVector(TestingSteering playerSteering) { if (GridGenerator.level != null && GridGenerator._currentEnd != null) { Debug.Log("Finding path"); List <Vector3> path = HierarchicalAStar.FindPath(GridGenerator.level, playerSteering.CurrentPosition - new Vector3(0, 1, 0), GridGenerator._currentEnd.transform.position); Debug.Log(path[1]); Vector3 nodePos = path[1]; if (nodePos == Vector3.zero) { nodePos = path[2]; if (nodePos == Vector3.zero) { nodePos = path[3]; } } Vector3 seekPosition = new Vector3(nodePos.x, playerSteering.CurrentPosition.y, nodePos.y); return(SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, seekPosition)); } return(Vector3.zero); }
void Start() { // PickableUpObject PickedUp = false; disposed = false; wander = GetComponent <WanderBehaviour>(); seek = GetComponent <SeekBehaviour>(); avoid = GetComponent <AvoidBehaviour>(); steering = GetComponent <DelegatedSteering>(); behaviour = new RobotBehaviour(this); board = UnityEngine.Object.FindObjectsOfType <BlackBoard>()[0]; CurrentBattery = FullBattery; CurrentTrash = null; PickedUpObject = null; behaviour.Start(); }
public override TaskState Run() { SeekBehaviour seekBe = m_Agent.GetComponent <SeekBehaviour>(); FleeBehaviour fleeBe = m_Agent.GetComponent <FleeBehaviour>(); m_Agent.maximumLinearVelocity = 1f; var pickups = FindObjectsOfType <HealthPickup>(); foreach (var pickup in pickups) { if (pickup.isEnabled) { seekBe.weight = 1; fleeBe.weight = 0; seekBe.targetTransform = pickup.transform; return(TaskState.SUCCESS); } } return(TaskState.FAILURE); }
/// <summary> /// Constructor for seek behaviour. /// </summary> /// <param name="behaviour"> /// Details for this behaviour. /// </param> /// <param name="parentBehaviour"> /// Reference to component to decorate. /// </param> public SeekBehaviourDecorator(AbstractBehaviourComponent parentBehaviour, MovementBehaviour behaviour) : base(parentBehaviour, behaviour) { this.behaviour = behaviour as SeekBehaviour; }
public void GroupBehaviours() { Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); foreach (var agent in swarmNeighbors) { if (!agent.Attacking) { _acceleration = BehaviourUpdate.BehaviourUpdated(WanderBehavior.WanderMove(agent.transform, enemyData.WanderRadius, enemyData.WanderDistance, enemyData.WanderJitter, 1.0f), enemyData.WanderBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(CohesionBehavior.CalculateMove(agent.transform, swarmNeighborsTrans), enemyData.CohesionBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(SeparationBehavior.SeparationMove(agent.transform, swarmNeighborsTrans, enemyData.SeparationBehaviorRadius), enemyData.SeparationBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(AlignmentBehavior.CalculateMove(agent.transform, swarmNeighborsTrans), enemyData.AlignmentBehaviorWeight); agent.Velocity += _acceleration * Time.deltaTime; if (agent.Velocity.magnitude > enemyData.MaxSpeed) { agent.Velocity.Normalize(); agent.Velocity *= enemyData.MaxSpeed; } if (agent.transform.position.x < _bottomLeft.position.x) { agent.Velocity *= -1; } if (agent.transform.position.x > _topright.position.x) { agent.Velocity *= -1; } if (agent.transform.position.y < _topright.position.y) { agent.Velocity *= -1; } if (agent.transform.position.y > _bottomLeft.position.y) { agent.Velocity *= -1; } //agent.transform.position += agent.Velocity * Time.deltaTime; } else { _acceleration = BehaviourUpdate.BehaviourUpdated(SeekBehaviour.SeekMove(agent.transform, agent.Target, enemyData.Swarm_AttackSpeed), enemyData.SeekBehaviorWeight); agent.Velocity += _acceleration * Time.deltaTime; } Vector3 deltaPos = agent.Velocity * Time.deltaTime; if (deltaPos.x == 0 && deltaPos.y == 0) { Debug.Log("Enemy is stuck!"); } agent.transform.position += agent.Velocity * Time.deltaTime; //_acceleration += (Vector3)(BehaviourUpdate.BehaviourUpdated(WallAvoidance.WallAvoidanceCalculation(agent.transform, _bottomLeft.position.x, _topright.position.x, _topright.position.y, _bottomLeft.position.y), enemyData.WallAvoidWeight)); } //transform.position += _velocity * Time.deltaTime; // { // move = BehaviourUpdate.BehaviourUpdated(CohesionBehavior.CalculateMove(agent.transform, swarmNeighbors), 5.0f); // move *= speed; // if (move.sqrMagnitude > squareMaxSpeed) // { // move = move.normalized * maxSpeed; // } // agent.transform.position += (Vector3)move * Time.deltaTime; // } }
public void SeekOn(BaseGameEntity goal, double intensity) { _seek = new SeekBehaviour(_movingEntity, goal); _dSeek = intensity; }
public void SeekOn(Vector2D destination, double intensity) { _seek = new SeekBehaviour(_movingEntity, destination); _dSeek = intensity; }
public void SeekOff() { _seek = null; _dSeek = 0; }
public CohesionBehaviour() { seek = new SeekBehaviour(); }
public AvoidLockOnRightLeftBehaviour( SteeringManager manager ) : base(manager) { this.tag = "AvoidLockOnRightLeft"; this.left = false; this.timeMax = 4.0f; this.radius = 200; this.dist = 400; this.pointOnSphere = Vector3.zero; this.sphere = new GameObject (); this.sphere.name = "AvoidLockOnSphere"; seek = new SeekBehaviour (manager); }
public FollowBehaviour(SteeringManager manager) : base(manager) { this.tag = "Follow"; seek = new SeekBehaviour(manager); }
public FollowBehaviour( SteeringManager manager ) : base(manager) { this.tag = "Follow"; seek = new SeekBehaviour (manager); }
// Use this for initialization void Start () { wanderDirection = 1; setNewDesiredPosition(); seekBehaviour = this.GetComponentInParent<SeekBehaviour>(); }
public TurnRight( SteeringManager manager ) : base(manager) { this.tag = "TurnRight"; this.left = false; this.timePassed = 20.0f; this.timeMax = 3.0f; this.radius = 200; this.dist = 600; this.pointOnSphere = Vector3.zero; pointOnSphere.x = 0.8f; pointOnSphere *= radius; this.sphere = new GameObject (); this.sphere.name = "AvoidLockOnSphere"; seek = new SeekBehaviour (manager); }
public TankSearchForPlayer() { seek = new SeekBehaviour(); path = new List <Cell>(); i = 0; }
public TankAttackPlayer() { seek = new SeekBehaviour(); }
public PursueBehaviour( SteeringManager manager ) : base(manager) { this.tag = "Pursue"; seek = new SeekBehaviour (manager); }