Inheritance: MonoBehaviour
コード例 #1
0
    public BabyDraggedState(StateMachine owner, SteeringBehavior steering, BabyStateScriptableObject stateData)
    {
        this.owner            = owner;
        this.steeringBehavior = steering;

        this.stateData = stateData;
    }
コード例 #2
0
ファイル: Vehicle.cs プロジェクト: jiwhan112/AI_Book
 public override void Active()
 {
     base.Active();
     mSteeringBehavior = new SteeringBehavior(this);
     mSteeringBehavior.SetOn(SteeringBehavior.SteerOption.SEEK);
     mSteeringBehavior.SetOn(SteeringBehavior.SteerOption.ARRIVE);
 }
コード例 #3
0
 public EnnemyFleeState(StateMachine owner, SteeringBehavior steering, EnnemyStateScriptableObject stateData)
 {
     this.owner            = owner;
     this.steeringBehavior = steering;
     fov            = owner.GetComponent <FieldOfView>();
     this.stateData = stateData;
 }
コード例 #4
0
ファイル: MovingEntity.cs プロジェクト: andyhebear/thinksharp
        public MovingEntity(Vector2D position,
                            double radius,
                            Vector2D velocity,
                            double max_speed,
                            Vector2D heading,
                            double mass,
                            Vector2D scale,
                            double turn_rate,
                            double max_force) : base(0, position, radius)
        {
            m_vHeading     = heading;
            m_vVelocity    = velocity;
            m_dMass        = mass;
            m_vSide        = m_vHeading.Perp();
            m_dMaxSpeed    = max_speed;
            m_dMaxTurnRate = turn_rate;
            m_dMaxForce    = max_force;
            m_vScale       = scale;

            m_OldPos           = new Vector2D();
            m_vSmoothedHeading = new Vector2D();

            m_intOldCellID = -1;

            m_pSteering = new SteeringBehavior(this);

            m_HeadingHistory     = new List <Vector2D>(SteerParams.Instance.NumSamplesForSmoothing);
            m_intNextHeadingSlot = 0;
        }
コード例 #5
0
 // Start is called before the first frame update
 void Start()
 {
     sb = GetComponent <SteeringBehavior>();
     sb.SeekOn(new Vector3(10, 1, 10));
     sb.WanderOn();
     //sb.ObstalceAvoidanceOn();
 }
コード例 #6
0
ファイル: LeaderFollowComponent.cs プロジェクト: senchov/ECS
    private void Start()
    {
        Steering       = new SteeringBehavior(MaxSpeed, MaxVel);
        FollowBehavior = new LeaderFollowBehavior(Steering, Behind);

        FillSquadPositions();
    }
コード例 #7
0
 public EnnemyEatingState(StateMachine owner, SteeringBehavior steering, Transform MouthTransform, EnnemyStateScriptableObject stateData)
 {
     this.owner            = owner;
     this.steeringBehavior = steering;
     this.mouthTransform   = MouthTransform;
     this.stateData        = stateData;
 }
コード例 #8
0
 private void Start()
 {
     ai          = GetComponent <SteeringBehavior>();
     rb          = GetComponent <Rigidbody>();
     line        = GetComponent <LineRenderer>();
     position    = rb.position;
     orientation = transform.eulerAngles.y;
 }
コード例 #9
0
    public EnnemyWanderState(StateMachine owner, SteeringBehavior steering, EnnemyStateScriptableObject stateData)
    {
        this.owner            = owner;
        this.steeringBehavior = steering;
        this.controller       = owner.GetComponent <EnnemyController>();
        fov = owner.GetComponent <FieldOfView>();

        this.stateData = stateData;
    }
コード例 #10
0
    public BabyIdleState(StateMachine owner, SteeringBehavior steering, PerimeterController perimeterController, BabyStateScriptableObject stateData)
    {
        this.owner               = owner;
        this.steeringBehavior    = steering;
        this.perimeterController = perimeterController;
        fov = owner.GetComponent <FieldOfView>();

        this.stateData = stateData;
    }
コード例 #11
0
    public BabyFollowState(StateMachine owner, SteeringBehavior steering, Transform leader, BabyStateScriptableObject stateData)
    {
        this.owner            = owner;
        this.steeringBehavior = steering;
        this.leaderToFollow   = leader;
        fov = owner.GetComponent <FieldOfView>();

        this.stateData = stateData;
    }
コード例 #12
0
 public void SetSteeringBehavior(SteeringBehavior behavior, int delay = 0)
 {
     if (behavior == null)
     {
         Debug.LogError("NULL");
     }
     m_SteeringBehavior = behavior;
     m_IsEnabled        = false;
     Invoke("Enable", delay);
 }
コード例 #13
0
    LineRenderer line;              // Used to draw circles and other things

    private void Start()
    {
        ai          = GetComponent <SteeringBehavior>();
        rb          = GetComponent <Rigidbody>();
        line        = GetComponent <LineRenderer>();
        position    = rb.position;
        orientation = transform.eulerAngles.y;
        maxSpeed    = 7;
        linear      = new Vector3(0, 0, 0);
        angular     = 0;
    }
コード例 #14
0
    // Start is called before the first frame up = nulldate
    void Start()
    {
        m_SteeringBehavior = new WanderBehavior();

        Color color = new Color(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f));

        foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>())
        {
            renderer.materials[0].color = color;
        }
    }
コード例 #15
0
    private void Start()
    {
        ai          = GetComponent <SteeringBehavior>();
        rb          = GetComponent <Rigidbody>();
        line        = GetComponent <LineRenderer>();
        position    = rb.position;
        orientation = transform.eulerAngles.y;

        GameObject[] wolfGroup = GameObject.FindGameObjectsWithTag("Wolf");

        red = GameObject.FindGameObjectWithTag("Red");
    }
コード例 #16
0
    public void Initialize(Type defaultState, SteeringBehavior steering)
    {
        ennemyStates.Add(typeof(EnnemyIdleState), new EnnemyIdleState(this, steering, perimeterController, idleStateData));
        ennemyStates.Add(typeof(EnnemyChaseState), new EnnemyChaseState(this, steering, chaseStateData));
        ennemyStates.Add(typeof(EnnemyFleeState), new EnnemyFleeState(this, steering, fleeStateData));
        ennemyStates.Add(typeof(EnnemyWanderState), new EnnemyWanderState(this, steering, wanderStateData));
        ennemyStates.Add(typeof(EnnemyEatingState), new EnnemyEatingState(this, steering, GetComponent <EnnemyController>().MouthTransform, eatingStateData));
        //ennemyStates.Add(typeof(EnnemyDeadState), new EnnemyDeadState());

        //ennemyStates.TryGetValue(typeof(EnnemyWanderState), out currentState);
        SetState(defaultState);
    }
コード例 #17
0
 public bool pathBoidLeader; // for path following, all other boids will follow leader
 private void Start()
 {
     ai           = GetComponent <SteeringBehavior>();
     rb           = GetComponent <Rigidbody>();
     line         = GetComponent <LineRenderer>();
     fieldManager = GameObject.FindGameObjectWithTag("gameManager");
     position     = rb.position;
     orientation  = transform.eulerAngles.y;
     if (phase == 4 || phase == 0)
     {
         redLead = GameObject.FindGameObjectWithTag("Red").GetComponent <PlayerController>();
     }
 }
コード例 #18
0
    public void Initialize(Type defaultState, Transform leader, SteeringBehavior steering)
    {
        babyStates.Add(typeof(BabyIdleState), new BabyIdleState(this, steering, perimeterController, idleStateData));
        babyStates.Add(typeof(BabyFollowState), new BabyFollowState(this, steering, leader, followStateData));
        babyStates.Add(typeof(BabyFleeState), new BabyFleeState(this, steering, fleeStateData));
        babyStates.Add(typeof(BabyWanderState), new BabyWanderState(this, steering, wanderStateData));
        babyStates.Add(typeof(BabyDraggedState), new BabyDraggedState(this, steering, draggedStateData));
        babyStates.Add(typeof(BabySafeState), new BabySafeState(this, steering, safeStateData));
        babyStates.Add(typeof(BabyDeadState), new BabyDeadState(this));

        babyStates.TryGetValue(typeof(BabyIdleState), out currentState);
        //SetState(defaultState);
    }
コード例 #19
0
    public override void FixedExecute()
    {
        //if the cell have not reach the teleport starting position, continue charge forward. If the cell
        //reach the teleport starting position, start the teleport corountine. The coroutine will disable the
        //enemy child cell for 1.5 second become teleport the enemy child cell to the next position and then
        //move towards the player main cell
        Vector2 Acceleration = Vector2.zero;

        if (m_bSqueezeDone && m_bTeleporting && !HasCellReachTargetPos(m_StartTelePos))
        {
            Acceleration += SteeringBehavior.Seek(m_Child, m_StartTelePos, 45f);
            if (m_Child.transform.localScale.y < 1f && m_Child.transform.localScale.x > 0.5f)
            {
                m_Child.transform.localScale += m_ShrinkRate;
            }
        }
        else if (m_bSqueezeDone && m_bTeleporting && HasCellReachTargetPos(m_StartTelePos))
        {
            m_bTeleported  = true;
            m_bTeleporting = false;
            m_ecFSM.StartChildCorountine(Teleport());
        }
        //If the cell has not reached the current target position, continue seek towards that target position and remain seperate from rest of the enemy child cells
        else if (m_bSqueezeDone && !HasCellReachTargetPos(m_CurrentTargetPoint.Position) && !m_bReachTarget)
        {
            Acceleration += SteeringBehavior.Arrive(m_Child, m_CurrentTargetPoint.Position, 0.03f);
            Acceleration += SteeringBehavior.Seperation(m_Child, TagNeighbours()) * 30f;
            if (m_Child.transform.localScale.y < 1f && m_Child.transform.localScale.x > 0.5f)
            {
                m_Child.transform.localScale += m_ShrinkRate;
            }
        }
        else if (m_bSqueezeDone && m_nCurrentTargetIndex + 1 < m_PathToTarget.Count && !m_bReachTarget)
        {
            m_nCurrentTargetIndex++;
            m_CurrentTargetPoint = m_PathToTarget[m_nCurrentTargetIndex];
        }
        //If the cell had reached the teleporting position and it hasn't teleported, start teleporting the cell to the calculated position
        else if (m_bSqueezeDone && HasCellReachTargetPos(m_PathToTarget[m_PathToTarget.Count - 1].Position) && m_bTeleporting == false && m_bTeleported == false)
        {
            m_bTeleporting = true;
        }

        //Clamp the acceleration of the enemy child cell to a maximum value and then add that acceleration force to the enemy child cell
        Acceleration = Vector2.ClampMagnitude(Acceleration, m_fMaxAcceleration);
        m_ecFSM.rigidbody2D.AddForce(Acceleration, ForceMode2D.Force);

        //Rotate the enemy child cell based on the direction of travel
        m_ecFSM.RotateToHeading();
    }
コード例 #20
0
ファイル: NPCController.cs プロジェクト: LyonLin27/Connect
    private void Start()
    {
        ai          = GetComponent <SteeringBehavior>();
        rb          = GetComponent <Rigidbody>();
        line        = GetComponent <LineRenderer>();
        position    = rb.position;
        orientation = transform.eulerAngles.y;
        //rotation = 0f;

        if (pathPoints.Count != 0)
        {
            ai.SetPath(pathPoints);
        }
    }
コード例 #21
0
 private void Awake()
 {
     initID();
     VehicleManager.RegisterVehicle(this);
     m_Steering           = new SteeringBehavior();
     m_Steering.m_vehicle = this;
     m_MaxSpeed           = 7;
     m_MaxForce           = 7;
     m_MaxTurnRate        = 1000;
     PanicDistance        = 10;
     sightAngle           = 2.0f;//大概120度
     sightRadius          = 10f;
     wanderTarget.transform.SetPositionAndRotation(transform.position, Quaternion.identity);
 }
コード例 #22
0
ファイル: Actor.cs プロジェクト: francot514/Wolf3dX
        public Actor(Map _map, Vector2 _position, CharacterDefinition newCharacterDefinition, int newActorID)
        {
            entityStateMachine = new StateMachine();

            // Idle doesn't need an end
            entityStateMachine.AddState(IDLE, IdleBegin, IdleTick, null);

            // Shooting doesn't need Begin or End.
            entityStateMachine.AddState(PATROLLING, null, PatrollingTick, null);

            entityStateMachine.AddState(CHASING_PLAYER, null, ChasingPlayerTick, null);
            entityStateMachine.AddState(ATTACKING, null, AttackingTick, null);
            entityStateMachine.AddState(SUFFERING_PAIN, null, SufferingPainTick, null);
            entityStateMachine.AddState(DYING, null, DyingTick, null);
            entityStateMachine.AddState(KILLED, null, KilledTick, null);

            characterDefinition = newCharacterDefinition;
            ActorID             = newActorID;

            script = new Script(this);

            //executes the init script if exists
            InitScript();
            AnimationName = "";

            //starts with the idle animation
            SetAnim("idle");
            time = 0;


            //copy the actor's attributes from the character definition

            MaxSpeed                   = characterDefinition.MaxSpeed;
            MaxForce                   = characterDefinition.MaxForce;
            HasPain                    = characterDefinition.HasPain;
            Score                      = characterDefinition.Score;
            WeaponType                 = characterDefinition.WeaponType;
            BoundingRadius             = 0.7f;
            MustGetCloseEnoughToAttack = characterDefinition.MustGetCloseEnoughToAttack;

            //TODO read the difficulty from the game variables
            HitPoints        = characterDefinition.HitPoints[(int)Difficulty.None];
            CurrentHitPoints = 0;
            Map = _map;

            MoveTo(_position);

            Behavior = new SteeringBehavior(this, _map);
        }
コード例 #23
0
        protected override void Compute()
        {
            if (!GameManager.Instance.StartRace)
            {
                return;
            }

            base.Compute();
            var target   = FindNextTarget();
            var steering = SteeringBehavior.Seek(transform.position, target, Rigidbody.velocity,
                                                 Speed);

            Rigidbody.AddForce(steering, ForceMode.Acceleration);
            AdjustRotation();
        }
コード例 #24
0
    private void Start()
    {
        ai      = GetComponent <SteeringBehavior>();
        rb      = GetComponent <Rigidbody>();
        line    = GetComponent <LineRenderer>();
        stopped = false;


        so = new SteeringOutput();
        k  = new Kinematic
        {
            position    = rb.position,
            velocity    = Vector3.zero,
            orientation = Mathf.Deg2Rad * rb.rotation.eulerAngles.y
        };
    }
コード例 #25
0
ファイル: UnitGroup.cs プロジェクト: xheugue/RTS_Project
    private SteeringBehavior getSlowestEntity()
    {
        float            minSpeed = float.MaxValue;
        SteeringBehavior min      = null;

        foreach (SteeringBehavior behavior in Group)
        {
            if (behavior.MaxSpeed < minSpeed)
            {
                minSpeed = behavior.MaxSpeed;
                min      = behavior;
            }
        }

        return(min);
    }
コード例 #26
0
    IEnumerator FollowPath()
    {
        bool followingPath = true;
        int  pathIndex     = 0;

        //transform.LookAt(path.lookPoints[0]);

        while (followingPath)
        {
            Vector2 pos2D = new Vector2(transform.position.x, transform.position.z);
            while (path.turnBoundaries[pathIndex].HasCrossedLine(pos2D))
            {
                if (pathIndex == path.finishLineIndex)
                {
                    followingPath       = false;
                    parent.currentSpeed = 0.0f;
                    break;
                }
                else
                {
                    pathIndex++;
                }
            }

            if (followingPath)
            {
                Vector3 targetPosition = path.lookPoints[pathIndex];
                Vector2 velocity2D     = SteeringBehavior.GetVelocity(new Vector2(targetPosition.x, targetPosition.z),
                                                                      transform.position, new Vector2(parent.velocity.x, parent.velocity.z),
                                                                      parent.maxSpeed, parent.turnSpeed, maxAvoidForce);
                parent.currentSpeed = velocity2D.magnitude;
                velocity2D.Normalize();

                Quaternion currentRotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(new Vector3(velocity2D.x, 0, velocity2D.y)), Time.deltaTime * parent.currentSpeed);

                parent.direction = currentRotation.eulerAngles;

                //sin == x and cos == y ??? they are flipped but works somehow.
                float dx = Mathf.Sin(parent.direction.y * Mathf.Deg2Rad);
                float dy = Mathf.Cos(parent.direction.y * Mathf.Deg2Rad);

                parent.velocity = parent.currentSpeed * new Vector3(dx, 0, dy);
            }

            yield return(null);
        }
    }
コード例 #27
0
 private void Start()
 {
     ai          = GetComponent <SteeringBehavior>();
     rb          = GetComponent <Rigidbody>();
     line        = GetComponent <LineRenderer>();
     ray         = GetComponent <LineRenderer>();
     position    = rb.position;
     orientation = transform.eulerAngles.y;
     //if (ai.tag == "Hunter")
     //{
     //    orientation = transform.eulerAngles.y-300;
     //}
     //else
     //{
     //    orientation = transform.eulerAngles.y + 300;
     //}
 }
コード例 #28
0
    public void OnDrawGizmos()
    {
#if UNITY_EDITOR
        Handles.color = Color.red;
        Handles.DrawWireDisc(owner.transform.position, owner.transform.up, stateData.fleeDistance);


        IBoid[] agentTab = SteeringBehavior.GetAllAgent();
        for (int i = 0; i < agentTab.Length; i++)
        {
            if (Vector3.Distance(owner.transform.position, agentTab[i].GetPosition()) <= stateData.fleeDistance)
            {
                Handles.DrawLine(owner.transform.position, agentTab[i].GetPosition());
            }
        }
#endif
    }
コード例 #29
0
 public FlyingEntity(Vector2D pos, Vector2D scale, Vector2D velocity, Vector2D heading, double radius, double mass, double maxSpeed, double maxForce, double maxTurnRate, BehaviorType behaviors)
 {
     Pos         = pos;
     Scale       = scale;
     Velocity    = velocity;
     Heading     = heading;
     Radius      = radius;
     Mass        = mass;
     MaxSpeed    = maxSpeed;
     MaxForce    = maxForce;
     MaxTurnRate = maxTurnRate;
     _behaviour  = new SteeringBehavior(this)
     {
         behaviours = behaviors
     };
     originalGoals = goals;
 }
コード例 #30
0
    public override void FixedExecute()
    {
        Vector2 Acceleration = Vector2.zero;

        if (!m_ecFSM.m_bHitWall)
        {
            if (m_ecFSM.IsHittingSideWalls())
            {
                m_ecFSM.m_bHitWall = true;
                m_ChildRB.velocity = Vector2.zero;
            }
            else if (m_CurrentIdleState == IdleStatus.Cohesion && !HasChildEnterMain(m_Child))
            {
                Acceleration += SteeringBehavior.Seek(m_Child, m_Main.transform.position, 20f);
            }
            else if (m_CurrentIdleState == IdleStatus.Seperate && !m_ecFSM.IsHittingSideWalls())
            {
                Acceleration += m_SeperateDirection.normalized * m_fIdleScale * 1.2f;
                Acceleration += m_MainRB.velocity;
                Acceleration += SteeringBehavior.Seperation(m_Child, TagNeighbours());
            }
        }
        else
        {
            if (!HasChildEnterMain(m_Child))
            {
                m_ChildRB.drag = 1f;
                Acceleration  += SteeringBehavior.Seek(m_Child, m_Main.transform.position, 10f);
            }
            else
            {
                m_ChildRB.velocity = m_MainRB.velocity;
            }
        }

        //Clamp the acceleration of the enemy child cell to a specific maximum of magnitude and add that acceleration as a force on to the enemy child cell
        Acceleration = Vector2.ClampMagnitude(Acceleration, m_fMaxMagnitude);
        m_ChildRB.AddForce(Acceleration);

        //Rotate the enemy child cell according to the specific direction of velocity it is enforced on
        if (!m_ecFSM.IsHittingSideWalls())
        {
            m_ecFSM.RotateToHeading();
        }
    }
コード例 #31
0
ファイル: Vehicle.cs プロジェクト: HuffyTomson/LittleBigBoy
 public Vehicle(GameObject _thisObj)
 {
     obj = _thisObj;
     rig = obj.GetComponent<Rigidbody>();
     steeringBehavior = new SteeringBehavior(this);
 }
コード例 #32
0
 public PropProxy(PropertyInfo prop, SteeringBehavior behavior, object defaultValue)
 {
     this.property = prop;
     this.behavior = behavior;
     property.SetValue(behavior, defaultValue, null);
 }
コード例 #33
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="b">Behavior</param>
 /// <param name="w">Weight</param>
 public BehaviorAndWeight(SteeringBehavior b, double w)
 {
     behavior = b;
     weight = w;
 }