示例#1
0
 void Die()
 {
     state = MovementStates.Dead;
     anim.SetTrigger("Die");
     GetComponent <Collider> ().enabled = false;
     Destroy(gameObject, 2);
 }
    //DropDown onValuechange functions
    public void DropDownManager(int index)
    {
        DeactivateAllControllers();           //Deactivate all controllers as we will reset them according to the dropdown value selected
        SetCameraDefaults();                  //Set default initial values of camera as it wil be overriden according to the dropdown value selected
        MovementState = MovementStates.None;  //Set this to none as it will be overriden according to according to the dropdown value selected
        tilting       = false;                //turn the tilting state to false as it will be overriden if respective dropdown is chosen.
        eventText.gameObject.SetActive(true); //Enable and reset the text to default
        eventText.text = eventDefaultText;

        //Setup events according to the dropdown value selected
        switch (index)
        {
        case 1:     //4-directional swipe
            SetUp4DirectionalSwipe();
            break;

        case 2:     //Tilt Controller
            SetUpTiltControls();
            break;

        case 3:     //Joystick and camera rotation
            SetUpJoystick();
            break;

        case 4:     //2d zoom and pan
            SetUp2DZoomAndPan();
            break;

        default:     //index 0 or any other option not specified
            hintText.text = hintDefaultText;
            break;
        }
    }
示例#3
0
    public void Init()
    {
        //Cache
        rb          = gameObject.GetComponent <Rigidbody2D>();
        animControl = gameObject.GetComponent <PlayerAnimController>();

        //Set initial variables
        gadgetCarried[0]        = GadgetTypes.FlashBang;
        currHealth              = settings.maxHealth;
        currHurtTime            = settings.maxHurtTime;
        numberOfPrimaryGadget   = 3;
        numberOfSecondaryGadget = 2;

        CheckLoadOut();
        CycleBetweenGuns();
        SetUpHealth();
        animControl.UpdatePlayergun();

        currMoveState = MovementStates.Idle;
        //Set input
        input = new Controls();
        input.PlayerControls.SetCallbacks(this);
        input.Enable();

        input.PlayerControls.Movement.canceled += _ => EndMovement();
        isInitialised = true;
    }
    // Use this for initialization
    new void Start()
    {
        base.Start();

        movementState    = MovementStates.Wandering;
        transform.parent = GameObject.Find("Zombies").transform;
    }
    public void SetMoveAnimations(MovementStates moveState)
    {
        switch (moveState)
        {
        case MovementStates.Idle:
            Animator.SetInteger("Speed", 0);
            break;

        case MovementStates.Moving:
            if (!CutsceneManagement.InCutscene)
            {
                if (Movement.WalkState != WalkStates.Sprint)
                {
                    Animator.SetInteger("Speed", 1);
                }
                else
                {
                    Animator.SetInteger("Speed", 2);
                }
            }
            break;

        default:
            break;
        }
    }
示例#6
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Ground")
     {
         moveState = MovementStates.GROUNDED;
     }
 }
示例#7
0
    void StateMachine(SearchStates searchStates, Vector3 allertedPosition)
    {
        if (movementStates == MovementStates.patrolling)
        {
            Patrolling();
        }
        if (searchStates == SearchStates.sawSomeone)
        {
            movementStates = MovementStates.chasing;

            Chasing(allertedPosition);
        }
        if (searchStates == SearchStates.idle)
        {
            movementStates = MovementStates.patrolling;
        }
        if (searchStates == SearchStates.heardSomething)
        {
            Searching(allertedPosition);
        }
        else
        {
            searchTimer = 0;
        }
    }
示例#8
0
 void Update()
 {
     mstate = GetComponent <Movement>().currentState;
     if (mstate == MovementStates.isMoving)
     {
         moveParticles.gameObject.SetActive(true);
         moveParticles.Play();
         if (!dashParticles.isPlaying)
         {
             dashParticles.Pause();
             dashParticles.gameObject.SetActive(false);
         }
     }
     else if (mstate == MovementStates.isDashing)
     {
         dashParticles.gameObject.SetActive(true);
         dashParticles.Play();
     }
     else if (mstate == MovementStates.isStill)
     {
         moveParticles.Pause();
         moveParticles.gameObject.SetActive(false);
         if (!dashParticles.isPlaying)
         {
             dashParticles.Pause();
             dashParticles.gameObject.SetActive(false);
         }
     }
 }
示例#9
0
    // Use this for initialization
    new void Start()
    {
        base.Start();

        lastShot      = Time.time;
        movementState = MovementStates.Wandering;
    }
示例#10
0
    void FixedUpdate()
    {
        if (GameStateManager.Instance.IsGamePaused())
        {
            return;
        }

        if (FrigthenModeActive() || !timerEnded())
        {
            return;
        }

        switch (enemyState)
        {
        case MovementStates.Chase:
            enemyState = MovementStates.Scatter;
            timer      = scatterModeDuration;
            break;

        case MovementStates.Scatter:
            enemyState = MovementStates.Chase;
            timer      = chaseModeDuration;
            break;
        }
    }
 void HandleVision()
 {
     if (vision.visibleTargets.Count > 0)
     {
         bool playWarningSound = true;
         for (int i = 0; i < vision.visibleTargets.Count; i++)
         {
             if (vision.visibleTargets[i].gameObject.GetComponent <EnemyAI>().state == EnemyAI.states.Angry)
             {
                 playWarningSound = false;
                 movementStatus   = PlayerController.MovementStates.running;
             }
         }
         if (playWarningSound)
         {
             timerCalmeMusicNow = 0;
             MusicManager.Play("Suspens", 5f);
         }
     }
     else
     {
         timerCalmeMusicNow += Time.deltaTime;
         if (timerCalmeMusicNow > timerCalmeMusic)
         {
             MusicManager.Play("Calme Tempete", 5f);
             movementStatus = PlayerController.MovementStates.walking;
         }
     }
 }
 private void SetUpJoystick()
 {
     //As joystick requires all three types of input controllers set them all to active
     Joystick.gameObject.SetActive(true);
     hintText.text = "Use the joystick to see its input value on screen or touch and drag on right side of the screen to rotate the camera in the desired direction. Supports only touch for camera rotation.";
     MovementState = MovementStates.Joystick; //Set the movement state to joystick
 }
示例#13
0
    void NextMovement()
    {
        if (anim.GetCurrentAnimatorStateInfo(0).IsName("GetHit"))
        {
            agent.SetDestination(transform.position);
        }
        else if (state == MovementStates.Follow && anim.GetCurrentAnimatorStateInfo(0).IsName("Run"))
        {
            agent.SetDestination(target.position);
        }

        if (Vector3.Distance(target.position, transform.position) >= 2f)
        {
            state = MovementStates.Follow;
        }
        else
        {
            transform.LookAt(target.position);
            state = MovementStates.Attack;
        }



        anim.SetInteger("state", (int)state);

        //Debug.Log (agent.nextPosition);
    }
示例#14
0
    void ChangeStates()
    {
        if (shiftKey)
        {
            if (movementState == MovementStates.Walking)
            {
                movementState = MovementStates.Running;
            }
            else
            {
                movementState = MovementStates.Walking;
            }
        }

        if (ctrlKey)
        {
            if (movementState != MovementStates.Crouching)
            {
                movementState = MovementStates.Crouching;
            }
            else
            {
                movementState = MovementStates.Walking;
            }
        }
    }
示例#15
0
        // Update is called once per frame
        void Update()
        {
            float theSpeed = moveSpeed;

            Vector3 movement = Vector3.zero;

            if (crouching)
            {
                theSpeed *= crouchSpeedMultiplier;
            }
            else if (Input.GetKey(KeyCode.LeftShift))
            {
                theSpeed *= runSpeedMultiplier;
            }

            if (Input.GetKey(KeyCode.W))
            {
                movement += stand.transform.forward * theSpeed;
            }
            if (Input.GetKey(KeyCode.S))
            {
                movement -= stand.transform.forward * theSpeed;
            }
            if (Input.GetKey(KeyCode.A))
            {
                movement -= stand.transform.right * theSpeed;
            }
            if (Input.GetKey(KeyCode.D))
            {
                movement += stand.transform.right * theSpeed;
            }

            if (Input.GetKeyDown(KeyCode.C) && canToggleCrouch)
            {
                StartCoroutine(CrouchCooldown());
            }
            // Un-crouch just by sprinting
            else if (crouching && Input.GetKey(KeyCode.LeftShift) && canToggleCrouch)
            {
                StartCoroutine(CrouchCooldown());
            }

            if (Input.GetKey(KeyCode.LeftShift) && moveState == MovementStates.Walking)
            {
                moveState = MovementStates.Running;
            }
            else if (!Input.GetKey(KeyCode.LeftShift) && movement.magnitude > 0)
            {
                moveState = MovementStates.Walking;
            }
            else if (movement.magnitude == 0)
            {
                moveState = MovementStates.Idle;
            }

            controller.Move((movement + gravity) * Time.deltaTime);

            PlayMovementSound();
        }
示例#16
0
 void DisplayMode()
 {
     if (oldEnemyState != enemyState)
     {
         displayMode.text = "Mode : " + enemyState;
         oldEnemyState    = enemyState;
     }
 }
示例#17
0
 void Start()
 {
     movementState   = MovementStates.MOVING_STRAIGHT;
     targetTransform = middleTransform;
     local           = allTransforms.transform.localPosition;
     pushbackTimer   = 0;
     player          = GameObject.FindGameObjectWithTag("Player");
 }
示例#18
0
    // Use this for initialization
    new void Start()
    {
        base.Start();

        movementState = MovementStates.Wandering;
        GetComponent <Renderer>().material = materials[Random.Range(0, materials.Length)];
        agent = GetComponent <NavMeshAgent>();
    }
示例#19
0
 void OnTriggerEnter(Collider Waypoint)
 {
     if (Waypoint.tag == "waypoint")
     {
         Destroy(WP);
         wayP         = false;
         MovementType = MovementStates.Idle;
     }
 }
示例#20
0
    // Use this for initialization
    void Start()
    {
        anim  = GetComponent <Animator> ();
        agent = GetComponent <NavMeshAgent> ();
        state = MovementStates.Idle;

        hp           = 2f;
        attackDamage = 1f;
    }
示例#21
0
 private GameStateMachine.GameState StatePlayerInMenu()
 {
     if (Input.GetKey(KeyCode.Space) || Input.GetKeyDown(KeyCode.Escape))
     {
         currentState = MovementStates.WaitingForPlayerInput;
         menuUI.SetActive(false);
     }
     return(GameStateMachine.GameState.Overworld);
 }
        public void Crouch()
        {
            controller.height = crouchHeight;
            moveSpeed         = crouchMovementSpeed;
            MovementState     = MovementStates.Crouching;

            _camera.transform.localPosition =
                new Vector3(_camera.transform.localPosition.x, -0.3f, _camera.transform.localPosition.z);
        }
示例#23
0
 /// <summary>
 /// Tries to begin an interaction with an overworld element. Returns true if there is something
 /// with which to be interacted.
 /// </summary>
 private bool HandleInteraction()
 {
     if (levelManager.EntityCanInteractWith(playerMovement.Index, playerMovement.Facing, out var index))
     {
         menuUI       = levelManager.InteractWith(index);
         currentState = MovementStates.PlayerInMenu;
         return(true);
     }
     return(false);
 }
示例#24
0
    /// <summary>
    /// Rotate the player. Sets currentState when rotation is complete.
    /// </summary>
    /// <returns></returns>
    private GameStateMachine.GameState StateRotatingPlayer()
    {
        // Rotate until facing the right direction
        if (playerMovement.Rotate())
        {
            currentState = MovementStates.WaitingForPlayerInput;
        }

        return(GameStateMachine.GameState.Overworld);
    }
示例#25
0
        public void RegisterState([NotNull] IMovementGeneratorState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            lock (SyncObj)
                MovementStates.Enqueue(state);
        }
示例#26
0
    void Update()
    {
        //Get current gamespeed from the timecontroller set in maincontroller and calculate bird avatar's movement speed
        //TODO: Null checks
        TimeController tc        = GameObject.Find("MainController").GetComponent <TimeController>();
        float          timeSpeed = tc.getTimeSpeed();

        calculatedMoveSpeed = moveSpeed * (int)timeSpeed;

        if (nextWaypoint)
        {
            Debug.DrawLine(transform.position, nextWaypoint.position, Color.green);
        }
        if (lastWaypoint)
        {
            Debug.DrawLine(transform.position, lastWaypoint.position, Color.black);
        }

        WaypointScript nextWp = nextWaypoint.GetComponent <WaypointScript> ();

        if (nextWp.stopPoint && currentState == MovementStates.MOVING)
        {
            this.currentState  = MovementStates.STOPPED;
            this.stoppedAtTime = tc.getCurrentDateTime();
            this.leaveTime     = stoppedAtTime.AddMinutes(nextWp.stopTimeInMinutes);
            nextWp.stopPoint   = false;
            if (nextWp.gameObject.GetComponent <PointOfInterest>() != null)
            {
                nextWp.gameObject.GetComponent <PointOfInterest>().show();
            }
        }

        if (currentState == MovementStates.STOPPED)
        {
            if (tc.getCurrentDateTime() >= leaveTime)
            {
                currentState = MovementStates.MOVING;
                if (nextWp.gameObject.GetComponent <PointOfInterest>() != null)
                {
                    nextWp.gameObject.GetComponent <PointOfInterest>().hide();
                }
            }
        }

        // move
        if (movingTowardsObject && currentState == MovementStates.MOVING)
        {
            MoveTowardsObject();
        }
        // Rotate towards object
        if (rotatingTowardsObject)
        {
            RotateTowardsObject();
        }
    }
 private void updateMovementState()
 {
     if (nearSoldiers.Count > 0 || nearCivilians.Count > 0)
     {
         movementState = MovementStates.Chasing;
     }
     else
     {
         movementState = MovementStates.Wandering;
     }
 }
    private void changeMovState(MovementStates state)
    {
        if (currentMovState != state)
        {
            prevMovState    = currentMovState;
            currentMovState = state;
        }


        //Debug.Log("Current State:" + currentMovState);
        //Debug.Log("PRev State:" + prevMovState);
    }
示例#29
0
    void Awake()
    {
        playerMovement = FindObjectOfType <PlayerMovement>();
        playerStats    = FindObjectOfType <PlayerStats>();
        levelManager   = FindObjectOfType <LevelManager>();

        currentState = MovementStates.WaitingForPlayerInput;

        movingEnemies = new HashSet <EnemyMovement>();
        movingCars    = new HashSet <CarMovement>();

        wasPlayerHitByCarThisTurn = false;
    }
示例#30
0
    protected override void Start()
    {
        base.Start();

        m_MovementState = MovementStates.IDLE;
        m_CanJump = false;
        m_JumpTimer = 0;
        
        if (m_Animator == null)
            m_Animator = GetComponent<Animator>();
        if (m_Rigidbody == null)
            m_Rigidbody = GetComponent<Rigidbody>();
    }
示例#31
0
    /// <summary>
    /// Tries to move the player in the indicated direction. Returns true if movement is possible.
    /// </summary>
    private bool HandleMovement(Direction direction)
    {
        var rotatedDirection = playerMovement.GetInputDirection(direction);

        if (levelManager.EntityCanMoveTo(playerMovement.Index, rotatedDirection, out var maybeNextIndex))
        {
            playerMovement.AcceptNextIndex(maybeNextIndex);
            currentState = MovementStates.MovingPlayer;
            return(true);
        }

        return(false);
    }
示例#32
0
    void Update()
    {
        //Get current gamespeed from the timecontroller set in maincontroller and calculate bird avatar's movement speed
        //TODO: Null checks
        TimeController tc = GameObject.Find ("MainController").GetComponent<TimeController>();
        float timeSpeed = tc.getTimeSpeed();
        calculatedMoveSpeed = moveSpeed * (int)timeSpeed;

        if(nextWaypoint)
            Debug.DrawLine(transform.position, nextWaypoint.position, Color.green);
        if(lastWaypoint)
            Debug.DrawLine(transform.position, lastWaypoint.position, Color.black);

        WaypointScript nextWp = nextWaypoint.GetComponent<WaypointScript> ();
        if (nextWp.stopPoint && currentState == MovementStates.MOVING) {
            this.currentState = MovementStates.STOPPED;
            this.stoppedAtTime = tc.getCurrentDateTime();
            this.leaveTime = stoppedAtTime.AddMinutes(nextWp.stopTimeInMinutes);
            nextWp.stopPoint = false;
            if(nextWp.gameObject.GetComponent<PointOfInterest>() != null) {
                nextWp.gameObject.GetComponent<PointOfInterest>().show();
            }
        }

        if (currentState == MovementStates.STOPPED) {
            if(tc.getCurrentDateTime() >= leaveTime) {
                currentState = MovementStates.MOVING;
                if(nextWp.gameObject.GetComponent<PointOfInterest>() != null) {
                    nextWp.gameObject.GetComponent<PointOfInterest>().hide();
                }
            }
        }

        // move
        if(movingTowardsObject && currentState == MovementStates.MOVING)
            MoveTowardsObject();
        // Rotate towards object
        if(rotatingTowardsObject)
            RotateTowardsObject();
    }
示例#33
0
        private void Self_OnChat(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourceType, string fromName, UUID id, UUID ownerid, Vector3 position)
        {
            if (id == client.Self.AgentID || message == "" || !message.StartsWith(FirstName))
                return;

            if (message.ToLower().Contains("go away"))
            {
                Disconnect();
                return;
            }

            if (message.ToLower().Contains("come here"))
            {
                Console.WriteLine("About to follow");

                GoToPosition(position);

                return;
            }

            if (message.ToLower().Contains("go to:"))
            {
                String dest = message.Substring(message.IndexOf(':') + 2);
                List<Vector3> wayPointList = WaypointService.GetWayPoints(client.Self.SimPosition, dest);
                TraverseWayPoints(wayPointList);
                return;
            }

            if (message.ToLower().Contains("follow"))
            {
                movementState = MovementStates.following;
                leaderID = avatarMap[id].LocalID;
                GoToPosition(position);
            }
        }
    void Update()
    {
        if(nextWaypoint)
            Debug.DrawLine(transform.position, nextWaypoint.position, Color.green);
        if(lastWaypoint)
            Debug.DrawLine(transform.position, lastWaypoint.position, Color.black);

        WaypointScript nextWp = nextWaypoint.GetComponent<WaypointScript> ();
        if (nextWp.stopPoint && currentState == MovementStates.MOVING) {
            this.currentState = MovementStates.STOPPED;
            this.stoppedAtTime = tc.getCurrentDateTime();
            this.leaveTime = stoppedAtTime.AddMinutes(nextWp.stopTimeInMinutes);
            nextWp.stopPoint = false;
            if(nextWp.gameObject.GetComponent<PointOfInterest>() != null) {
                nextWp.gameObject.GetComponent<PointOfInterest>().show();
            }
        }

        if (currentState == MovementStates.STOPPED) {
            if(tc.getCurrentDateTime() >= leaveTime) {
                currentState = MovementStates.MOVING;
                if(nextWp.gameObject.GetComponent<PointOfInterest>() != null) {
                    nextWp.gameObject.GetComponent<PointOfInterest>().hide();
                }
            }
        }

        // move
        if(movingTowardsObject && currentState == MovementStates.MOVING)
            MoveTowardsObject();
        // Rotate towards object
        if(rotatingTowardsObject)
            RotateTowardsObject();
    }
示例#35
0
 /// <summary>
 /// Метод задающий точку к которой необходим двигаться
 /// </summary>
 /// <param name="vector">Точка на НавМеше</param>
 protected virtual void SetTarget(Vector3 vector)
 {
     if (Agent.enabled)
     {
         Agent.Resume();
         MovementState = MovementStates.Move;
         Agent.SetDestination(vector);
     }
 }
示例#36
0
 /// <summary>
 /// Метод заставляет преследовать объект
 /// </summary>
 /// <param name="target">Преследуемый объект</param>
 protected virtual void SetTarget(Transform target)
 {
     if (Agent.enabled)
     {
         Agent.Resume();
         MovementState = MovementStates.Follow;
         _currentTarget = target;
         Agent.SetDestination(target.position);
     }
 }
示例#37
0
    void Awake()
    {
        //Find and set the first waypoint
        SetFirstWaypoint ();

        //Initialize calculatedMoveSpeed to the default moveSpeed
        calculatedMoveSpeed = moveSpeed;

        //Set the bird avatar in motion
        currentState = MovementStates.MOVING;
        rotatingTowardsObject = true;
        movingTowardsObject = true;

        randomWaypoints = new List<Transform>();
        visitedWaypoints = new List<Transform>();
    }
示例#38
0
        protected void GoToPosition(Vector3 position)
        {
            // Don't try to go 2 places at once.

            if (movementState == MovementStates.moving)
                return;

            MovementStates oldState = movementState;
            movementState = MovementStates.moving;

            float lastX = client.Self.SimPosition.X;
            float lastY = client.Self.SimPosition.Y;
            System.Threading.Thread.Sleep(100);

            client.Self.Movement.TurnToward(position);
            client.Self.Movement.SendUpdate();
            System.Threading.Thread.Sleep(500);
            Console.WriteLine("movement: " + client.Self.Movement);
            Console.WriteLine("updateInterval: " + client.Self.Movement.UpdateInterval);

            client.Self.Movement.Stop = false;
            client.Self.Movement.AtPos = true;
            client.Self.Movement.SendUpdate();

            int openTries = 0;
            while ( reset == false &&
                   (Math.Abs(client.Self.SimPosition.X - position.X) > 1 ||
                    Math.Abs(client.Self.SimPosition.Y - position.Y) > 1))
            {
                client.Self.Movement.TurnToward(position);
                client.Self.Movement.Stop = false;
                client.Self.Movement.AtPos = true;
                client.Self.Movement.SendUpdate();
                System.Threading.Thread.Sleep(100);
                //Console.WriteLine("Still not to " + position + ", now at: " + client.Self.SimPosition);

                if ((Math.Abs(client.Self.SimPosition.X - lastX) < .0001 ||
                     Math.Abs(client.Self.SimPosition.Y - lastY) < .0001))
                {
                    // We've hit a wall or door, try to open it by touching it.
                    if (openTries < 6)
                    {
                        openTries++;
                        Console.WriteLine("Trying to open");
                        foreach (KeyValuePair<UUID, Primitive> kvp in objectMap)
                        {
                            if ((Math.Abs(kvp.Value.Position.X - client.Self.SimPosition.X) < openTries) &&
                               (Math.Abs(kvp.Value.Position.Y - client.Self.SimPosition.Y) < openTries))
                            {
                                //client.Self.Chat("Trying to touch " + kvp.Value.Properties.Name, 0, ChatType.Normal);
                                client.Self.Touch(kvp.Value.LocalID);
                            }
                        }

                        lastX = client.Self.SimPosition.X;
                        lastY = client.Self.SimPosition.Y;
                        System.Threading.Thread.Sleep(500);
                        //Console.WriteLine("atPos: " + client.Self.Movement.AtPos);
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("opening failed");
                        //Console.WriteLine("atPos: " + client.Self.Movement.AtPos);
                        openTries = 0;
                        reset = true;
                        break;
                    }
                }

                openTries = 0;
                lastX = client.Self.SimPosition.X;
                lastY = client.Self.SimPosition.Y;
            }

            client.Self.Movement.Stop = true;
            client.Self.Movement.AtPos = false;
            client.Self.Movement.AtNeg = false;
            client.Self.Movement.LeftPos = false;
            client.Self.Movement.LeftNeg = false;
            client.Self.Movement.SendUpdate();
            reset = false;
            movementState = oldState;

            return;
        }
示例#39
0
 /// <summary>
 /// Атаковать объект. Если он слишком далеко, то преследовать сначала
 /// </summary>
 /// <param name="target">Кого атаковать</param>
 protected virtual void Attack(Transform target)
 {
     Stop();
     _currentTarget = target;
     MovementState = MovementStates.Attack;
     Animator.SetBool("Attack", true);
 }
示例#40
0
 protected virtual void Stop()
 {
     MovementState = MovementStates.Stop;
     if (Agent.enabled)
         Agent.Stop();
 }