public void Initialize() { _rb = GetComponent <Rigidbody2D>(); _followBehaviour = new SteeringBehaviour(_rb, _steeringData); _moveActive = true; SetMovementType(_type); }
// Calculates all forces from attached SteeringBehaviours void ComputeForces() { // Reset force before calculation force = Vector3.zero; // Loop through all behaviours for (int i = 0; i < behaviours.Count; i++) { // Get current behaviour SteeringBehaviour b = behaviours[i]; // Check if behaviour is active and enabled if (!b.isActiveAndEnabled) { // Skip over to next behaviour continue; } // Apply behaviour's force to our final force force += b.GetForce() * b.weighting; // Check if force has gone over maxSpeed if (force.magnitude > maxSpeed) { // Cap the force down to maxSpeed force = force.normalized * maxSpeed; // Exit for loop break; } } }
/// <summary> /// the requester must have an target for this to work as intended /// </summary> protected Vector2 ApplyAvoidance(AIAgent requester, Vector2 requesterPosition, Vector2 currentDesiredPostion, bool linearWeight, int anglesRangeToIgnore) { Vector2 des = requester.Destination; Vector2?avoidanceTemp; AIAgent avoidanceObj; if (perpendicular) { avoidanceTemp = SteeringBehaviour.ObstacleAvoidance(requester, requesterPosition, (currentDesiredPostion - requesterPosition).normalized, out avoidanceObj); } else { avoidanceTemp = SteeringBehaviour.ObstacleAvoidance(requester, requesterPosition, out avoidanceObj); } if (UseObstacleAvoidance(requester, avoidanceTemp, avoidanceObj, des, anglesRangeToIgnore)) { float avoidanceWeight = GetAvoidanceWeight(requester, requesterPosition, avoidanceObj.transform.position, linearWeight); currentDesiredPostion = Vector2.Lerp(currentDesiredPostion, avoidanceTemp.Value, avoidanceWeight * requester.data.aviodanceWieghtMultiplier); } return(currentDesiredPostion); }
public Attack(GameObject agent, GameObject enemy) : base(agent, TaskType.Attack) { this.enemy = enemy; steeringBehaviour = agent.GetComponent <SteeringBehaviour>(); stats = agent.GetComponent <Stats>(); remainingCooldownTime = 0.0f; }
private void Awake() { steering = new SteeringBehaviour(this); InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation); SetNoTargetState(); }
public void EnableFollowPlayer() { // Change body color to blue renderer.GetPropertyBlock(propBlock); propBlock.SetColor("_Color", new Color(0, 0, 1, 1)); renderer.SetPropertyBlock(propBlock, 0); // Set behaviour to follow player trail and set followtarget behaviour = SteeringBehaviour.Follow; fleeTimer = minFleeSeconds; if (!PlayerController.Instance.minionTrail.Contains(gameObject)) { PlayerController.Instance.minionTrail.Add(gameObject); } if (PlayerController.Instance.minionTrail[0] == this.gameObject) { followTarget = PlayerController.Instance.transform; } else { int index = PlayerController.Instance.minionTrail.IndexOf(gameObject); followTarget = PlayerController.Instance.minionTrail[index - 1].transform; } }
public DynamicObstacleAvoidance(float _avoidDistance, float _lookahead, SteeringBehaviour _s, float _maxAcceleration) { avoidDistance = _avoidDistance; lookahead = _lookahead; s = _s; maxAcceleration = _maxAcceleration; }
public DynamicPathFollowing(Path _path, float _pathOffset, Transform _currentParam, SteeringBehaviour _s) { path = _path; pathOffset = _pathOffset; currentParam = _currentParam; s = _s; }
void ComputeForces() { // SET force to zero force = Vector3.zero; // FOR i := 0 to behaviours count for (int i = 0; i < behaviours.Count; i++) { // IF behavior is enabled SteeringBehaviour behaviour = behaviours[i]; if (!behaviour.enabled) { continue; } // SET force to force + behaviour force force += behaviour.GetForce() * behaviour.weighting; // IF force is greater than maxVelocity if (force.magnitude > maxVelocity) { // SET force to force normalized x maxVelocity force = force.normalized * maxVelocity; // BREAK break; } } }
private void Update() { _direction += SteeringBehaviour.Seek(TargetPosition, _rb.velocity, this) * Time.deltaTime; _direction = SteeringBehaviour.Arriving(this, _direction, TargetPosition, distanceToArriveAtTargetLocation, 0.6f); //_movement.MoveTowards(_rb, TargetPosition, Time.deltaTime); _movement.AssignVelocity(_rb, Vector3.ClampMagnitude(_direction, _maxSpeed)); if (rotateForwardToDirection) { //var rotation = Quaternion.identity; _rb.transform.LookAt(_movement.LastDirectionFacing + _rb.position, Vector3.up); var newRotation = _rb.transform.rotation; if (lockRotationX) { newRotation.x = 0; } if (lockRotationY) { newRotation.y = 0; } if (lockRotationZ) { newRotation.z = 0; } _rb.transform.rotation = newRotation; } Debug.DrawLine(_rb.transform.position, _movement.LastDirectionFacing + _rb.transform.position, Color.blue); }
void ComputeForces() { // reset the force force = Vector3.zero; //Loop through all behaviours attached to gameobject for (int i = 0; i < behaviours.Count; i++) { SteeringBehaviour behaviour = behaviours[i]; if (!behaviour.isActive) { continue; } // Calculate the force from it force += behaviour.GetForce() * behaviour.weighting; //If the force are too big if (force.magnitude > maxVelocity) { //Clamp it to the nax force = force.normalized * maxVelocity; //stop calculating break; } } }
void ComputeForces() { // SET force to zero force = Vector3.zero; // When you create a variable in a function, // It only exists within that function. // FOR i = 0 to behaviours length for (int i = 0; i < behaviours.Length; i++) { SteeringBehaviour behaviour = behaviours[i]; // IF behaviour is not enabled if (!behaviour.enabled) { // CONTINUE continue; } // SET force to force + behaviour's force force += behaviour.GetForce(); // IF force is greater than maxVelocity if (force.magnitude > maxVelocity) { // SET force to force normalized x maxVelocity force = force.normalized * maxVelocity; // BREAK break; } } }
void ComputeForces() { // SET force to zero force = Vector3.zero; // FOR i = 0 to behaviours count for (int i = 0; i < behaviours.Length; i++) { SteeringBehaviour behaviour = behaviours[i]; // IF behaviour is not enabled if (!behaviour.enabled) { // CONTINUE continue; } // SET force to force + behaviour's force force += behaviour.GetForce(); // IF force is greater than maxVelocity if (force.magnitude > maxVelocity) { // SET force to force normalized x maxVelocity force = force.normalized * maxVelocity; // BREAK break; } } }
public void SummonObject(Vector3 summonPosition) { SteeringBehaviour holderSummon = Instantiate(summonableObject, summonPosition, Quaternion.identity).GetComponent <SteeringBehaviour>(); holderSummon.followTransform = this.transform; holderSummon.isAutomated = true; }
public override void Update(float timeElapsed) { // First step calculate steering force Vector2D steeringForce = this.SB.Calculate(); // If the ObstacleAvoidance returns something that is not null. overrule the steeringforce. this.SB = new ObstacleAvoidance(this); Vector2D _avoidance = this.SB.Calculate(); if (_avoidance != null) { steeringForce = _avoidance; } // Second step divide by the mass of the moving entity Vector2D Acceleration = steeringForce.Divide(this.Mass); // add the acceleration to the velocity (multiply by timeElapsed) this.Velocity.Add(Acceleration.Multiply(timeElapsed)); // truncate the velocity back to regular speeds this.Velocity.truncate(this.MaxSpeed); // update the current position; this.Pos.Add(this.Velocity); Console.WriteLine(ToString()); }
private void actuadorHumanoNoDriftin() { if (selectedBehaviour != antiDorifto) { this.velocidad = Vector3.zero; antiDorifto = selectedBehaviour; } }
public void addSteeringBehaviour(SteeringBehaviour behaviour, float weight) { weights.Add(new SteeringWeight() { weight = weight, behaviourName = behaviour.getName() }); behaviours.Add(behaviour); }
public void RemoveSteering(SteeringBehaviour steer) { if (steers.Contains(steer)) { steers.Remove(steer); Destroy(steer); } }
// Use this for initialization void Awake() { my_SteeringBehaviour = GetComponent <SteeringBehaviour>(); my_SteeringBehaviour.SetVehicle(this); rig = GetComponent <Rigidbody>(); boxCollider = GetComponent <BoxCollider>(); taggedObstacles = new List <GameObject>(); }
private void Awake() { steering = new SteeringBehaviour(this); InitVehicle(VehiclePrefab, WeaponPrefab, transform.position, transform.rotation); SetNoTargetState(); speechCooldown = Random.Range(minSpeechTime, maxSpeechTime); }
internal override void newTaskLowWA(SteeringBehaviour st) { kinetic.Clear(); WallAvoidance3WhiswersSD wall = new WallAvoidance3WhiswersSD(); wall.mult = 0.5f; kinetic.Add(wall); kinetic.Add(st); }
void Awake() { playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth> (); playerTransform = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); anim = GetComponent <Animator>(); dogTransform = GetComponent <Transform> (); rdb2 = GetComponent <Rigidbody2D> (); seek = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour; }
void Awake() { playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth> (); waypoint1 = GameObject.Find("Waypoint7").GetComponent <Transform> (); waypoint2 = GameObject.Find("Waypoint8").GetComponent <Transform> (); helliTransform = GetComponent <Transform> (); rdb2 = GetComponent <Rigidbody2D> (); seek = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour; }
private void OnDestroy() { //Debug.Log("ActorMover Destroy :" + gameObject.name); GameWorld.instance.RemoveAgent(aiAgent); aiAgent = null; steeringBehaviour = null; m_pHeadingSmoother = null; }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform> (); playerHealth = player.GetComponent <PlayerHealth> () as PlayerHealth; rdb = GetComponent <Rigidbody2D> (); guardCollider = GetComponent <BoxCollider2D>(); anim = GetComponent <Animator> (); seek = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour; } //Awake
internal override void addTask(SteeringBehaviour st) { List <SteeringBehaviour> newTasks = new List <SteeringBehaviour>(); newTasks.Add(new WallAvoidance3WhiswersSD()); newTasks.Add(st); newTasks.AddRange(kinetic.GetRange(1, kinetic.Count - 1)); kinetic.Clear(); kinetic = new List <SteeringBehaviour>(newTasks); }
public void AddBehaviours(SteeringBehaviour steeringBehaviour) { if (_steeringBehaviours == null) { SetBehaviour(steeringBehaviour); } else { _steeringBehaviours.Add(steeringBehaviour); } }
void UpdateArrival() { var leaderPos = (Vector2)leader.transform.position; var leaderDir = SteeringBehaviour.GetDirection(leader); var arrivalTarget = leaderPos - leaderDir * behindDistance; arrival.enabled = true; arrival.SetTarget(arrivalTarget); }
public RandomRoam() : base(new SteeringBehaviour()) { SteeringBehaviours = new SteeringBehaviour { EnableObjectAvoidance = true, EnableWallAvoidance = true, Seek = true, Wander = false }; Navigation = new AStar(); }
void Awake() { girlTransform = GetComponent <Transform> (); girlRigidBody = GetComponent <Rigidbody2D> (); anim = GetComponent <Animator> (); playerTransform = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform> (); playerHealth = playerTransform.GetComponent <PlayerHealth> () as PlayerHealth; pathPoints = GameObject.Find("Pathpoints").GetComponentsInChildren <Transform> (); controlPoints = GameObject.Find("Points").GetComponentsInChildren <Transform> (); seek = ScriptableObject.CreateInstance("SteeringBehaviour") as SteeringBehaviour; } //Awake
// unity methods void Start() { moving = false; grounded = true; previously_grounded = true; movement_direction = Vector3.zero; body = GetComponent<Rigidbody>(); movement = GetComponent<SteeringBehaviour>(); original_max_speed = movement.max_speed; }
public void AddBehaviour(SteeringBehaviour b) { behaviours.Add(b); }
public void RemoveBehaviour(SteeringBehaviour b) { behaviours.Remove(b); }
// Use this for initialization void Start() { m_velocity = getAngle(); m_steering = new SteeringBehaviour(); }
public void removeSteeringBehaviour(SteeringBehaviour behaviour) { steeringBehaviours.Remove(behaviour); }
// Core functions public void addSteeringBehaviour(SteeringBehaviour behaviour) { steeringBehaviours.Add (behaviour); }