public override SteeringOutput.SteeringOutput getSteering() { Vector2 direction = Target.getPosition() - Character.getPosition(); float distance = direction.sqrMagnitude; float speed = Character.getVelocity().sqrMagnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / maxPrediction; } AgentMeta dummy = new AgentMeta(new Vector2(0.0f, 0.0f) + Target.getVelocity() * prediction); Behaviour seek = new Seek(dummy, Character); SteeringOutput.SteeringOutput steering = seek.getSteering(); return(steering); }
// Use this for initialization private void Awake() { _rb = GetComponent <Rigidbody>(); _steeringBasics = GetComponent <SteeringBasics>(); _seek = GetComponent <Seek>(); SteeringBasics.RbConstraints(_rb); }
public Steering Apply() { Steering st = new Steering(); if (finished) { callback(true); return(st); } if (followPath.HasPath()) { if (Time.fixedTime - timeStamp > reconsiderSeconds) { timeStamp = Time.fixedTime; SetNewTarget(target, false); } } else { st += Seek.GetSteering(target, agent, 500f); //If path has not been solved yet just do Seek. } st += followPath.Apply(); //If there is no path just avoid collisions return(st); }
public static Steering GetSteering(Agent npc, float threshold, float decayCoefficient, float maxAccel, bool visibleRays) { Steering steering = new Steering(); int neighbours = 0; Vector3 centerOfMass = Vector3.zero; int layerMask = 1 << 9; Collider[] hits = Physics.OverlapSphere(npc.position, threshold, layerMask); foreach (Collider coll in hits) { //Comprobar con un SphereCast, en vez de Tag quiza usar Layers Agent agent = coll.GetComponent <Agent>(); float distance = Util.HorizontalDist(agent.position, npc.position); if (agent != npc && distance < threshold) { centerOfMass += agent.position; neighbours++; } } if (neighbours > 0) { centerOfMass /= neighbours; return(Seek.GetSteering(centerOfMass, npc, maxAccel, visibleRays)); } return(steering); }
public Steering GetSteering() { if (path == null || currentPoint >= path.Length) { if (path == null) { Debug.LogError("Path is invalid: Null"); } if (currentPoint >= path.Length) { Debug.LogError("Path is invalid: Out of bounds"); } return(new Steering()); } UpdateExtraRadius(); float arrivalRadius2 = arrivalRadius + extraRadius; float distance = Util.HorizontalDist(path[currentPoint], npc.position); if (distance < arrivalRadius2) { if (currentPoint != Mathf.Min(currentPoint + 1, path.Length - 1)) { extraRadius = 0; near = false; } currentPoint = Mathf.Min(currentPoint + 1, path.Length - 1); //When it reaches the last stays on it //if (currentPoint == path.Length - 2) // return Arrive.GetSteering(path[currentPoint], npc, 1f, maxAccel /*50*/); } return(Seek.GetSteering(path[currentPoint], npc, maxAccel /*50*/, false)); }
// Start is called before the first frame update protected override void Start() { moveTypeSeek = new Seek(); moveTypeSeek.character = this; moveTypeSeek.target = target; moveTypeFlee = new Seek(); moveTypeFlee.flee = true; moveTypeFlee.character = this; moveTypeFlee.target = target; moveTypeEvade = new Evade(); moveTypeEvade.character = this; moveTypeEvade.target = target; moveTypeAvoid = new ObstacleAvoidance(); moveTypeAvoid.character = this; moveTypeAvoid.target = target; rotateTypeFace = new Face(); rotateTypeFace.character = this; rotateTypeFace.target = target; rotateTypeLWYG = new LookWhereYoureGoing(); rotateTypeLWYG.character = this; rotateTypeLWYG.target = target; }
new protected void Start() { base.Start(); Seek seeking = GetComponent <Seek> (); seeking.Target = target.position; }
void CreateLeaders(Vector3 newpos) { GameObject leader = GameObject.Instantiate <GameObject> (prefab); leader.transform.parent = this.transform; leader.transform.position = this.transform.TransformPoint(newpos); leader.transform.rotation = this.transform.rotation; Seek seek = leader.AddComponent <Seek> (); seek.enabled = !seek.enabled; Boid b = leader.GetComponent <Boid> (); b.maxSpeed = 6.5f; for (int i = 1; i <= followers; i++) { Vector3 offset = new Vector3(gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); offset = new Vector3(-gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); } }
// Use this for initialization protected override void Start() { Sight = GetComponent <FieldOfView>(); Search = GetComponent <AStarSearch>(); Path = GetComponent <ASPathFollower>(); Wander = GetComponent <Wander>(); Seek = GetComponent <Seek>(); Flee = GetComponent <Flee>(); Arrive = GetComponent <Arrive>(); Terrain = GameObject.Find("Terrain"); Animator = GetComponent <Animator>(); SearchAgent = GetComponent <ASAgent>(); State = new FiniteStateMachine <Velociraptor>(this); State.Change(V_Idle.Instance); Path.enabled = true; Path.path = new ASPath(); Path.enabled = false; collision_ticks = 0.0f; health_time = 0.0f; hunger_time = 0.0f; thirst_time = 0.0f; base.Start(); }
public SeekToPosition(Agent agent, Vector3 destination) : base(agent, GoalTypes.SeekToPosition) { _destination = destination; _seek = new Seek(agent.Kinematic, destination); _look = new FaceHeading(agent.Kinematic); }
public override IEnumerator Enter(Machine owner, Brain controller) { mainMachine = owner; myBrain = controller; Legs myLeg = myBrain.legs; arriveBehaviour = new PathfindToPoint(); seekBehaviour = new Seek(); arriveBehaviour.Init(myLeg,myBrain.levelGrid); seekBehaviour.Init(myLeg); myLeg.addSteeringBehaviour(arriveBehaviour); myLeg.addSteeringBehaviour(seekBehaviour); //set speed back to normal myBrain.legs.maxSpeed = 5f; if(firstActivation) { //set cowardLevel for sheep. Random.value returns a random number between 0.0 [inclusive] and 1.0 [inclusive]. float coward = 0.5f; myBrain.memory.SetValue("cowardLevel", coward); myBrain.memory.SetValue("chasedBy", new List<Brain>()); myBrain.memory.SetValue("BeingEaten", false); myBrain.memory.SetValue("HP", 100f); firstActivation = false; } time = 0f; seekingTime = 0f; yield return null; }
public override SteeringOutput.SteeringOutput getSteering() { Vector2 direction = Target.getPosition() - Character.getPosition(); float distance = direction.magnitude; float speed = Character.getVelocity().magnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / maxPrediction; } GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy")); AgentMeta dummyAgent = dummy.GetComponent <AgentMeta> (); dummyAgent.setPosition(Target.getPosition() + Target.getVelocity() * prediction); Behaviour seek = new Seek(dummyAgent, Character); SteeringOutput.SteeringOutput steering = seek.getSteering(); MonoBehaviour.Destroy(dummy); return(steering); }
public override void OnEnter(AIState previousState) { base.OnEnter(previousState); waitUntil = float.MinValue; seek = this.Behaviors.OfType <Seek>().First(); var obstacles = Level.Instance.GetObstaclesAround(CreatureTransform.position, CoverSearchDistance); if (obstacles.Count > 0) { var obstacle = obstacles[UnityEngine.Random.Range(0, obstacles.Count)]; Vector3 toCrew = this.CrewPos - obstacle.transform.position; var behindObstacle = toCrew.normalized * 1.5f; seek.Goal = obstacle.transform.position - behindObstacle; Instantiate(DebugExplosion, seek.Goal, Quaternion.identity); } else { this.StateManager.ActivateState <PunkerNewPos>(); } }
//Function to create leader ships void CreateLeaders(Vector3 newpos) { GameObject leader = GameObject.Instantiate <GameObject> (prefab); leader.transform.parent = this.transform; leader.transform.position = this.transform.TransformPoint(newpos); leader.transform.rotation = this.transform.rotation; //add steering behaviours Wander w = leader.AddComponent <Wander>(); Seek seek = leader.AddComponent <Seek> (); seek.enabled = !seek.enabled; //disable seek behaviour ObstacleAvoidance obavd = leader.AddComponent <ObstacleAvoidance> (); //Change speed of boid Boid b = leader.GetComponent <Boid> (); b.maxSpeed = 2; //Create followers of leader for (int i = 1; i <= followers; i++) { Vector3 offset = new Vector3(gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); offset = new Vector3(-gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); } }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent>(); path = new NavMeshPath(); seek = new Seek(); seek.target.position = Input.mousePosition; }
public override SteeringOutput.SteeringOutput getSteering() { Vector2 direction = Target.position - Character.position; float distance = direction.magnitude; float speed = Character.velocity.magnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / maxPrediction; } AgentMeta dummyAgent = new AgentMeta(); dummyAgent.position = Target.position + Target.velocity * prediction; Behaviour seek = new Seek(dummyAgent, Character); SteeringOutput.SteeringOutput steering = seek.getSteering(); /* Limpiar y devolver resultados */ MonoBehaviour.Destroy(dummyAgent); return(steering); }
// Use this for initialization protected override void Start() { waterSource = GameObject.Find("Daylight Water"); thirst = 100; health = 100; energy = 100; currentState = ankyState.IDLE; ankyWander = GetComponent <Wander>(); ankyFlee = GetComponent <Flee>(); ankyView = GetComponent <FieldOfView>(); ankyFace = GetComponent <Face>(); ankyFaceEnemy = GetComponent <FaceEnemy>(); ankyPursue = GetComponent <Pursue>(); ankySeek = GetComponent <Seek>(); ankyAgent = GetComponent <Agent>(); anim = GetComponent <Animator>(); // Assert default animation booleans and floats anim.SetBool("isIdle", true); anim.SetBool("isEating", false); anim.SetBool("isDrinking", false); anim.SetBool("isAlerted", false); anim.SetBool("isGrazing", false); anim.SetBool("isAttacking", false); anim.SetBool("isFleeing", false); anim.SetBool("isDead", false); anim.SetFloat("speedMod", 1.0f); // This with GetBool and GetFloat allows // you to see how to change the flag parameters in the animation controller base.Start(); }
void Awake() { anim = GetComponent <Animator>(); sprite = GetComponent <SpriteRenderer>(); body = GetComponent <Rigidbody2D>(); seekTargetScript = GetComponent <Seek>(); }
// Update is called once per frame void FixedUpdate() { var targetPosition = _headsetTransform.localToWorldMatrix.MultiplyPoint(Offset); targetPosition.y = Mathf.Clamp( targetPosition.y, _headsetTransform.position.y - .2f, _headsetTransform.position.y + .2f ); var steeringForce = Seek.Calculate(transform.position, targetPosition, MaxSpeed); // Calculate velocity _velocity = Vector3.ClampMagnitude(steeringForce / Mass * Time.fixedDeltaTime, MaxSpeed); // Add velocity to position transform.position += _velocity; // Add continuous rotation transform.eulerAngles = new Vector3( transform.eulerAngles.x, transform.eulerAngles.y + RotationSpeed, transform.eulerAngles.z ); }
public void ChangeState(UnitStates newState) { currentState = newState; switch (currentState) { case UnitStates.Idle: DestroyImmediate(fleeScript); DestroyImmediate(seekScript); break; case UnitStates.Flee: fleeScript = gameObject.AddComponent <Flee>(); fleeScript.target = target; fleeScript.enabled = true; DestroyImmediate(seekScript); break; case UnitStates.Seek: cohesionScript.weight = 0.7f; seperationScript.weight = 50.0f; seekScript = gameObject.AddComponent <Seek>(); seekScript.target = target; seekScript.enabled = true; DestroyImmediate(fleeScript); break; } }
private void btnVal_Click(object sender, System.EventArgs e) { double Seek; Seek = ourAudio.CurrentPosition; txtVal.Text = Seek.ToString(); }
// Start is called before the first frame update void Start() { mySeek = new Seek(); mySeek.character = this; mySeek.target = target; myFlee = new Flee(); myFlee.character = this; myFlee.target = target; myArrv = new Arrive(); myArrv.character = this; myArrv.target = target; myAlgn = new Align(); myAlgn.character = this; myAlgn.target = target; myFace = new Face(); myFace.character = this; myFace.target = target; myLWYG = new LookWhereGoing(); myLWYG.character = this; myLWYG.target = target; myFPth = new FollowPathDemo(); myFPth.character = this; myFPth.path = waypointList; //myFPth.target = target; }
public RunFromTargets(SteeringOutput SteeringAgent, Kinetics KineticsAgent, Kinetics[] KineticsTargets, float MaxAccel) { steeringAgent = SteeringAgent; kineticsAgent = KineticsAgent; kineticsTargets = KineticsTargets; seek = new Seek(kineticsAgent, kineticsTargets[0], MaxAccel); }
public void Awake() { TraversalMargin = 3; movingEntity = GetComponent <MovingEntity>(); aiController = GetComponent <AiController>(); seek = GetComponent <Seek>(); arrive = GetComponent <Arrive>(); }
private void Start() { blackboard = GetComponent <ChargingEnemyBlackboard>(); wanderPlusAvoid = GetComponent <WanderPlusAvoid>(); seek = GetComponent <Seek>(); enemyPassiveFsm = GetComponent <ChargingEnemyPassiveFSM>(); enemyCol = GetComponent <CapsuleCollider>(); }
public void SeekOn(Transform targetTrans) { if (!behaviours.Contains(Seek.GetInstance())) { behaviours.Add(Seek.GetInstance()); } TargetTrans = targetTrans; }
public AIState(Agent _agent, Wander _wander, Flee _flee, Seek _seek, Face _face) { agent = _agent; wander = _wander; flee = _flee; seek = _seek; face = _face; }
void Start() { base.Start(); seeker = gameObject.AddComponent <Seek>(); seeker.active = true; seeker.target = target; influencers.Add(seeker); }
public static Seek GetInstance() { if (instance == null) { instance = new Seek(); } return(instance); }
public FollowTarget(SteeringOutput SteeringAgent, Kinetics KineticsAgent, Kinetics KineticsTarget, float MaxAccel) { steeringAgent = SteeringAgent; kineticsAgent = KineticsAgent; kineticsTarget = KineticsTarget; seek = new Seek(kineticsAgent, kineticsTarget, MaxAccel); }
public TraverseEdge(Agent agent, Edge edgeToTraverse) : base(agent, GoalTypes.SeekToPosition) { //this.edgeToTraverse = edgeToTraverse; _destination = edgeToTraverse.ToNode.Position; _seek = new Seek(agent.Kinematic, _destination); _look = new FaceHeading(agent.Kinematic); }
private Seek getSeekBehaviour() { if (seek == null) { seek = new Seek(); seek.Init (this.getLegs ()); } return seek; }
public override IEnumerator Enter(Machine owner, Brain controller) { mainMachine = owner; myBrain = controller; Legs myLeg = myBrain.legs; runTo = new Seek(); runTo.Init(myLeg); player = GameObject.FindGameObjectWithTag("Player").transform; hiddenTime = 0; myBrain.memory.SetValue ("shouldHide", 0f); myBrain.legs.maxSpeed = 11f; myLeg.addSteeringBehaviour(runTo); yield return null; }
/// <summary> /// Creates a new instance /// </summary> public Behaviors() { Alignment = new Alignment(); Arrive = new Arrive(); Cohesion = new Cohesion(); Evade = new Evade(); Flee = new Flee(); Hide = new Hide(); Interpose = new Interpose(); ObstacleAvoidance = new ObstacleAvoidance(); OffsetPursuit = new OffsetPursuit(); PathFollowing = new PathFollowing(); Pursuit = new Pursuit(); Seek = new Seek(); Separation = new Separation(); WallAvoidance = new WallAvoidance(); Wander = new Wander(); }
public override IEnumerator Enter(Machine owner, Brain controller) { mainMachine = owner; myBrain = controller; Legs myLeg = myBrain.legs; arriveBehaviour = new PathfindToPoint(); seekBehaviour = new Seek(); arriveBehaviour.Init(myLeg, myBrain.levelGrid); seekBehaviour.Init(myLeg); myLeg.addSteeringBehaviour(arriveBehaviour); myLeg.addSteeringBehaviour(seekBehaviour); myLeg.maxSpeed = 11f; time = 0f; ferocityRate = controller.memory.GetValue<float>("ferocity"); sheepTarget = myBrain.memory.GetValue<SensedObject>("hasCommand"); sheepMemory = sheepTarget.getMemory(); sheepBrain = (Brain)sheepTarget.getObject().GetComponent("Brain"); arriveBehaviour.setTarget(sheepTarget.getObject()); //for machine learning float panic = sheepBrain.memory.GetValue<float>("Panic"); float courage = sheepBrain.memory.GetValue<float>("cowardLevel"); float chasedBy = sheepBrain.memory.GetValue<List<Brain>>("chasedBy").Count; float distanceWithMe = Vector2.Distance(sheepBrain.legs.getPosition(), myBrain.legs.getPosition()); float distanceWithSheperd = Vector2.Distance(sheepBrain.legs.getPosition(), ((Legs)GameObject.FindGameObjectWithTag("Player").GetComponent<Legs>()).getPosition()); float hungry = myBrain.memory.GetValue<float>("hungryLevel"); float sheepHP = sheepBrain.memory.GetValue<float>("HP"); string sheep = panic + "," + courage + "," + chasedBy + "," + distanceWithMe + "," + distanceWithSheperd + "," + hungry + "," + sheepHP; myBrain.memory.SetValue("targeting", sheep); yield return null; }
void Awake() { steeringAgent = GetComponent<SteeringAgent>(); steeringSeek = GetComponent<Seek>(); steeringArrive = GetComponent<Arrive>(); //steeringFlee = GetComponent<SteeringFlee>(); //steeringWander = GetComponent<SteeringWander>(); steeringAgent.enabled = true; //Wander(); InitBT(); bt.Start(); }
/// <summary> /// Seek a new postion. /// Seek to some place in the movie. /// Seek.Relative is a relative seek of +/- value seconds (default). /// Seek.Percentage is a seek to value % in the movie. /// Seek.Absolute is a seek to an absolute position of value seconds. /// </summary> /// <param name="value"></param> /// <param name="type"></param> public void Seek(int value, Seek type) { MediaPlayer.StandardInput.WriteLine(string.Format("seek {0} {1}", value, type)); MediaPlayer.StandardInput.Flush(); }
/// <summary> /// Seek a new postion. /// Seek to some place in the movie. /// Seek.Relative is a relative seek of +/- value seconds (default). /// Seek.Percentage is a seek to value % in the movie. /// Seek.Absolute is a seek to an absolute position of value seconds. /// </summary> /// <param name="value"></param> /// <param name="type"></param> public void Seek(int value, Seek type) { Debug.WriteLine(DateTime.Now.ToLongTimeString() + " MPLAYER Seek. {1} type, {0} seconds", value, type.ToString()); MediaPlayer.StandardInput.WriteLine(string.Format("pausing_keep_force seek {0} {1}", value, (int)type)); MediaPlayer.StandardInput.Flush(); }
public bool Get(Seek seek, out object key, out object value) { Data dkey = Data.New(); Data dvalue = Data.New(); try { int ret = funcs.get(cursorp, ref dkey, ref dvalue, (uint)seek); if (ret == DB_NOTFOUND || ret == DB_KEYEMPTY) { key = null; value = null; return false; } CheckError(ret); key = dkey.GetObject(parent.binfmt, parent.KeyType); value = dvalue.GetObject(parent.binfmt, parent.ValueType); return true; } finally { dkey.Free(); dvalue.Free(); } }
public void Awake() { TraversalMargin = 3; movingEntity = GetComponent<MovingEntity>(); aiController = GetComponent<AiController>(); seek = GetComponent<Seek>(); arrive = GetComponent<Arrive>(); }
protected void characterStart(){ //script of same GameObject initiation seekScript = GetComponent<Seek> (); arriveScript = GetComponent<Arrive> (); steeringScript = GetComponent<SteeringAgent> (); alignScript = GetComponent<Align> (); ai = GetComponent<SorcererAI>(); playerNetworkScript = GetComponent<CharacterNetworkScript>(); basicAttackScript = GetComponent<BasicAttack> (); sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.renderer.castShadows = false; sphere.renderer.receiveShadows = false; sphere.transform.parent = transform; sphere.transform.localScale = new Vector3 (1.0f, 1.0f, 1.0f); sphere.gameObject.layer = LayerMask.NameToLayer ("Minimap"); accuracy = 0.8f; attacking = false; stopMoving (); }
// Use this for initialization protected virtual void Start() { graph = GetComponent<Graph> (); agent = GetComponent<SteeringAgent> (); seekScript = GetComponent<Seek> (); arriveScript = GetComponent<Arrive> (); characterNode = GetComponent<Node> (); openList = new List<Node>(); closedList = new List<Node>(); path = new List<Node> (); pathIndex = 0; DontDestroyOnLoad (gameObject); }