Inheritance: MonoBehaviour
Example #1
0
    void Update()
    {
        // Store the input axes.
        h = Input.GetAxis("Horizontal");
        v = Input.GetAxis("Vertical");

        // Set the input axes on the Animator Controller.
        anim.SetFloat(hFloat, h, 0.1f, Time.deltaTime);
        anim.SetFloat(vFloat, v, 0.1f, Time.deltaTime);

        // Toggle sprint by input.
        sprint = Input.GetButton(sprintButton);

        // Set the correct camera FOV for sprint mode.
        if (IsSprinting())
        {
            changedFOV = true;
            camScript.SetFOV(sprintFOV);
        }
        else if (changedFOV)
        {
            camScript.ResetFOV();
            changedFOV = false;
        }
        // Set the grounded test on the Animator Controller.
        anim.SetBool(groundedBool, IsGrounded());
    }
Example #2
0
 void Start()
 {
     _surroundings = GetComponent <CharacterSurroundings>();
     _input        = GetComponent <CharacterInput>();
     _flip         = GetComponent <CharacterFlip>();
     _player       = GameObject.Find("Player");
 }
Example #3
0
        public override void Update()
        {
            base.Update();

            //Check for how long to slide
            //TOOD: LATER CHANGE TO HOW FAR SLIDE BASED ON TRACK SPEED AND DISTANCE COVERED
            if (timer < waitTime)
            {
                timer += Time.deltaTime;
            }

            //Change back to running state after slide over
            else
            {
                controller.ChangeState(Enums.CharacterStateType.Running);
            }

            //If jump input then jump from slide
            if (CharacterInput.SwipeUpInput())
            {
                controller.ChangeState(Enums.CharacterStateType.Jumping);
            }


            //Apply gravity so player falls from top if sliding whenver he is not on ground
            //Check for fast falling if we want to continue to slide from fast fall
            if (!controller.IsGrounded && !controller.IsFastFalling)
            {
                controller.ChangeState(Enums.CharacterStateType.Falling);
            }
        }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (interactionHolder.Interaction)
        {
            // set the pInventoryScript to hold the player's inventory
            CharacterInput cInputRef = interactionHolder.CharacterReference;
            pInventoryScript = cInputRef.gameObject.GetComponent <PlayerInventory>();

            if (materialPickUp != "")
            {
                pInventoryScript.AddToInventory(materialPickUp, matPickUpAmount);
            }

            if (modKeyPickUp != "")
            {
                pInventoryScript.AddToInventory(modKeyPickUp);
            }

            if (toolPickUp != null)
            {
                pInventoryScript.AddToInventory(toolPickUp);
            }

            Destroy(this.gameObject);
        }
    }
Example #5
0
 // Use this for initialization
 void Start()
 {
     input         = GetComponentInParent <CharacterInput>();
     weaponHandler = GetComponentInParent <WeaponHandler>();
     netman        = GameObject.Find("AdvancedNetworkManager").GetComponent <AdvancedNetworkManager>();
     Settings.SetActive(false);
 }
Example #6
0
        public override void Update()
        {
            base.Update();

            //In air
            if (!controller.IsGrounded)
            {
                //apply gravity to make character fall
                controller.ApplyGravity();

                //FastFall when swipe down
                if (CharacterInput.SwipeDownInput())
                {
                    controller.FastFall();

                    //Change from jump state to slide state on fast fall
                    controller.ChangeState(Enums.CharacterStateType.Sliding);
                }

                //If character reaches max height and starts falling
                //TODO: LATER CHANGE TO HOW FAR JUMP INSTEAD BASED ON TRACK SPEED
                else if (controller.CheckForFall())
                {
                    //Change from jump state to fall state
                    controller.ChangeState(Enums.CharacterStateType.Falling);
                }
            }
        }
Example #7
0
        public override void Update()
        {
            base.Update();

            //Check for ground
            if (controller.IsGrounded)
            {
                //Snap back to ground while grounded
                //controller.SnapToGround();

                //Jump
                if (CharacterInput.SwipeUpInput())
                {
                    //Change from this state to jump state
                    controller.ChangeState(Enums.CharacterStateType.Jumping);
                }

                //Slide
                else if (CharacterInput.SwipeDownInput())
                {
                    //Change from this state to slide state
                    controller.ChangeState(Enums.CharacterStateType.Sliding);
                }
            }

            //If falling from top of something while running
            else
            {
                //Change from this state to fall state
                controller.ChangeState(Enums.CharacterStateType.Falling);
            }
        }
Example #8
0
    protected override IEnumerator BehaviourCoroutine()
    {
        Vector3 axis = Vector3.zero;

        axis   = Camera.main.transform.TransformVector(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")));
        axis.y = 0;
        axis.Normalize();
        animator.CrossFade("roll", 0.25f);
        unitInfo.ChangeState(UnitInfo.UnitState.action);
        CharacterMovement movement = unitInfo.GetComponent <CharacterMovement>();
        CharacterInput    input    = unitInfo.GetComponent <CharacterInput>();

        input.SetZoomAble(false);


        SetStopActionEvent(delegate()
        {
            input.SetZoomAble(true);
            if (CharacterInput.GetMovingInput() == Vector3.zero)
            {
                movement.Stop();
            }
        });

        if (axis == Vector3.zero)
        {
            axis = unitInfo.transform.forward;
        }
        movement.transform.rotation = Quaternion.LookRotation(axis);
        movement.StopRotating();
        movement.Move(axis, speed, speed, speed);
        yield return(new WaitForStateChange(this, 2));

        StopAction();
    }
Example #9
0
 void Start()
 {
     menuController = GetComponent <MenuController>();
     playerInput    = player.GetComponent <CharacterInput>();
     enemySpawner.SetPlayer(player.transform);
     LeaveGame();
 }
Example #10
0
    // Start is called before the first frame update
    void Start()
    {
        audioSource = GetComponent <AudioSource>();
        player      = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterInput>();

        player.OnPlayerStateChanged += OnPlayerStateChanged_EH;
    }
    public void OnMove(ref CharacterInput input)
    {
        input.horizontal = Random.Range(-1f, 1f);
        input.vertical   = Random.Range(-1f, 1f);

        input.bombDrop = Random.Range(0, 2) == 1 ? true : false;
    }
Example #12
0
    public void Initiolize(SampleController sampleController)
    {
        characterStatus = sampleController.characterStatus;
        targetLook      = sampleController.cameraHandler.targetLook;
        cameraSystem    = sampleController.cameraHandler.mainTransform.gameObject;
        noPlayerMask    = sampleController.cameraHandler.noPlayerMask;
        cam             = sampleController.cameraHandler.cameraTransform.gameObject;
        anim            = sampleController.anim;
        characterInput  = sampleController.characterInput;
        characterFight  = sampleController.characterFight;
        characterIK     = sampleController.characterIK;
        ammoSlider      = sampleController.ammoSlider;

        if (characterFight != null)
        {
            sword = Instantiate(fightWeapon.weaponPrefab, fightPoint);
            ReturnSwordToPos();
            activeFightWeapon          = sword.GetComponent <FightWeapon>();
            characterInput.fightWeapon = activeFightWeapon;
            characterFight.weapon      = activeFightWeapon;

            anim.SetBool("Weapon", true);
            anim.SetInteger("WeaponType", 0);
            fighter = true;
        }
        itemText.text = string.Empty;
    }
Example #13
0
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         player = null;
     }
 }
Example #14
0
 void Start()
 {
     input            = GetComponent <CharacterInput>();
     controllerMove   = GetComponent <SimpleWalkerController>();
     cinmachineCamera = GetComponent <CinemachineControllerCamera>();
     StartCoroutine(LoadDataPlayer());
 }
Example #15
0
 // Lifecycle
 private void Awake()
 {
     rb    = GetComponent <Rigidbody2D>();
     anim  = GetComponent <Animator>();
     col   = GetComponent <Collider2D>();
     input = GetComponent <CharacterInput>();
 }
Example #16
0
    void Start()
    {
        spider = GetComponentInParent <Spider>();
        input  = GetComponentInParent <CharacterInput>();

        ChangeType(limbType);

        if (isArm)
        {
            target.localPosition = new Vector3(0, armHeight, 0);

            randomAmount /= 4;
        }

        defPos = (Vector2)target.localPosition;

        if (Application.isPlaying)
        {
            target.localPosition = target.localPosition + (Vector3)(Random.insideUnitCircle * randomAmount);
        }

        currPos = defPos + (Vector2)transform.position;

        if (GetComponent <SortingGroup>())
        {
            GetComponent <SortingGroup>().sortingOrder = Mathf.RoundToInt(transform.localPosition.y * -10);
        }
    }
Example #17
0
        internal void SetCharacterInput(BepuUtilities.Memory.BufferPool bufferpool, int bodyHandle, Simulation simulation)
        {
            characterControllers = new Demos.Demos.Characters.CharacterControllers(bufferpool);
            collider.bodyHandle  = bodyHandle;

            characterInput = new CharacterInput(characterControllers, bodyHandle, simulation, this.Position, new Capsule(0.5f, 1), 0.1f, 1, 20, 100, 6, 4, MathF.PI * 0.4f);
        }
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);

        for (int i = 0; i < 4; i++)
        {
            characterInputs[i] = new CharacterInput(i);
        }

        joyXAxis       = new string[8];
        joyButton0     = new KeyCode[8];
        joyButton1     = new KeyCode[8];
        joyButtonStart = new KeyCode[8];
        for (int i = 0; i < 8; i++)
        {
            joyXAxis[i] = "Joy" + (i + 1) + "X";
            // Reference for joystick buttons: http://wiki.unity3d.com/index.php?title=Xbox360Controller
            joyButton0[i] = (KeyCode)System.Enum.Parse(typeof(KeyCode),
                                                       "Joystick" + (i + 1) + "Button0");
            joyButton1[i] = (KeyCode)System.Enum.Parse(typeof(KeyCode),
                                                       "Joystick" + (i + 1) + "Button1");
            joyButtonStart[i] = (KeyCode)System.Enum.Parse(typeof(KeyCode),
                                                           "Joystick" + (i + 1) + "Button7");
        }
        allKeys = (KeyCode[])System.Enum.GetValues(typeof(KeyCode));

        SceneManager.sceneLoaded += OnSceneChange;
    }
Example #19
0
    // Deal with the basic player movement
    void MovementManagement(float horizontal, float vertical)
    {
        // On ground, obey gravity.
        if (behaviourManager.IsGrounded())
        {
            behaviourManager.GetRigidBody.useGravity = true;
        }

        // Call function that deals with player orientation.
        Rotating(horizontal, vertical);

        // Set proper speed.
        Vector2 dir = new Vector2(horizontal, vertical);

        speed = Vector2.ClampMagnitude(dir, 1f).magnitude;
        // This is for PC only, gamepads control speed via analog stick.
        speedSeeker += Input.GetAxis("Mouse ScrollWheel");
        speedSeeker  = Mathf.Clamp(speedSeeker, walkSpeed, runSpeed);
        speed       *= speedSeeker;
        if (behaviourManager.IsSprinting())
        {
            speed = sprintSpeed;
        }

        behaviourManager.GetAnim.SetFloat(speedFloat, speed, speedDampTime, Time.deltaTime);
    }
Example #20
0
 private void Awake()
 {
     if (!Input)
     {
         m_CharacterInput = gameObject.AddComponent <DummyInput>();
     }
 }
Example #21
0
        /// <summary>
        /// 1. Check for fast fall input
        /// 2. Check for ground if falling from top of something
        /// </summary>
        public override void Update()
        {
            base.Update();

            //Falling from air
            if (!controller.IsGrounded)
            {
                //Apply gravity to fall
                controller.ApplyGravity();

                //FastFall and slide
                if (CharacterInput.SwipeDownInput())
                {
                    controller.FastFall();

                    //Change from falling state to running state
                    controller.ChangeState(Enums.CharacterStateType.Sliding);
                }
            }

            //Reached ground
            else
            {
                //Change from falling state to running state
                controller.ChangeState(Enums.CharacterStateType.Running);
            }
        }
Example #22
0
    public IEnumerator ShowWallJump()
    {
        // Start the cutscene
        CharacterInput input = GetComponent <CharacterInput>();

        input.UpdateInputMethod       = null;
        GameManager.IsPlayingCutscene = true;
        GameManager.MainCamera.Target = transform;

        // Do the walljump
        input.Horizontal = -1;
        yield return(new WaitForSeconds(1.15f));

        input.Horizontal = 0;
        input.Jump       = new Vector2(-1, 1);
        GameManager.MainCamera.Target = null;
        yield return(new WaitForSeconds(0.2f));

        input.Jump = Vector2.zero;
        yield return(new WaitForSeconds(0.7f));

        input.Jump = new Vector2(1, 1);
        yield return(new WaitForSeconds(1.5f));

        input.Jump = new Vector2(1, 1);

        // End the cutscene
        GameManager.MainCamera.Target = GameManager.Player.transform;
        GameManager.IsPlayingCutscene = false;
        gameObject.SetActive(false);
    }
Example #23
0
    public static CharacterState Move(CharacterState previous, CharacterInput input, float speed, int timestamp, Transform _transformToMove)
    {
        //update transform rotation
        _transformToMove.rotation = input.rotation;

        //calculate movement vector
        //horizontal movement
        Vector3 movement = GetMovement(_transformToMove, input, speed);
        //calculate the next movement
        CharacterState state;

        //if the position is valid, accept it
        if (ValidatePredictedState(input.predictedResult, previous.position + movement))
        {
            state = new CharacterState
            {
                position  = input.predictedResult,
                rotation  = input.rotation,
                moveNum   = previous.moveNum + 1,
                timestamp = timestamp
            };
        }
        else
        {
            state = new CharacterState
            {
                position  = movement + previous.position,
                rotation  = input.rotation,
                moveNum   = previous.moveNum + 1,
                timestamp = timestamp
            };
        }

        return(state);
    }
Example #24
0
 // Use this for initialization
 void Start()
 {
     tr              = transform;
     mover           = GetComponent <Mover>();
     characterInput  = GetComponent <CharacterInput>();
     cameraTransform = Camera.main.transform;
 }
Example #25
0
    void Start()
    {
        charIn = GetComponent <CharacterInput>();
        body   = GetComponent <Rigidbody>();
        sec    = after_sec;

        EventManager.gainPower += GainPower;
    }
Example #26
0
    void Start()
    {
        input = input ?? GetComponent <CharacterInput>();
        Debug.Assert(input != null);

        characterController = characterController ?? GetComponent <CharacterController>();
        Debug.Assert(characterController != null);
    }
Example #27
0
    void Start()
    {
        input = GetComponentInParent <CharacterInput>();

        eyeTimer = Random.Range(1, randomEyeTime);

        eyelash.gameObject.SetActive(false);
    }
Example #28
0
 // Update is used to set features regardless the active behaviour.
 void Update()
 {
     // Get jump input.
     if (!jump && Input.GetButtonDown(jumpButton) && behaviourManager.IsCurrentBehaviour(this.behaviourCode) && !behaviourManager.IsOverriding())
     {
         jump = true;
     }
 }
Example #29
0
 public void Initiolize(SampleController sampleController)
 {
     rotateMode      = true;
     step            = Time.fixedDeltaTime * cameraConfig.pivotSpeed;
     defaultMask     = cam.cullingMask;
     characterStatus = sampleController.characterStatus;
     characterInput  = sampleController.characterInput;
 }
    public void Initialize(CharacterAnimation animation, CharacterEquipment equipment, CharacterInput input)
    {
        this.animation = animation;
        this.equipment = equipment;
        this.input     = input;

        currentHealth = maxHealth;
    }
    void CmdSetServerInput(CharacterInput.InputState[] newInputs, Vector3 newClientPos)
    {
        int index = 0;

        //Server: Input received but state not consecutive with the last one ACKed
        if (newInputs.Length > 0 && newInputs[index].inputState > clientInputState + 1)
        {
            Debug.LogWarning("Missing inputs from " + clientInputState + " to " + newInputs[index].inputState);
        }

        //Server: Discard all old states (state already ACK from the server)
        while (index < newInputs.Length && newInputs[index].inputState <= clientInputState)
        {
            index++;
        }

        //Server: Run through all received states to execute them
        while (index < newInputs.Length)
        {
            //Server: Set the character input
            characterInput.currentInput = newInputs[index];
            //Server: Set the client state number
            clientInputState = newInputs[index].inputState;
            //Server: Run update for this step according to received input
            if (!isLocalPlayer)
            {
                characterMovement.RunUpdate(Time.fixedDeltaTime);
                characterRotation.RunUpdate(Time.fixedDeltaTime);
            }

            index++;
        }

        //Check on server that position received from client isn't too far from the position calculated locally
        //TODO: maybe add a cheat check here
        if (Vector3.Distance(newClientPos, transform.position) > MAX_CLIENT_DISTANCE_WARNING) {
            Debug.LogWarning("Client distance too far from player (maybe net condition are very bad or move code isn't deterministic)");
        }

        //Server: Send to other script that state update finished
        SendMessage("ServerStateReceived", clientInputState, SendMessageOptions.DontRequireReceiver);
    }
Example #32
0
    private void ActivateInteractive(CharacterInput.Button button)
    {
        InteractiveTerminal terminal = currentInteractive as InteractiveTerminal;
        if (terminal != null)
        {
            bool terminalActivated = false;

            switch (button)
            {
                case CharacterInput.Button.A:
                {
                    terminalActivated = terminal.Activate(InteractiveTerminal.TerminalType.A);
                    break;
                }
                case CharacterInput.Button.B:
                {
                    terminalActivated = terminal.Activate(InteractiveTerminal.TerminalType.B);
                    break;
                }
                case CharacterInput.Button.X:
                {
                    terminalActivated = terminal.Activate(InteractiveTerminal.TerminalType.X);
                    break;
                }
                case CharacterInput.Button.Y:
                {
                    terminalActivated = terminal.Activate(InteractiveTerminal.TerminalType.Y);
                    break;
                }
                default:
                {
                    break;
                }
            }

            if (terminalActivated)
            {
                playInteractionAnimation = true;
                isInteracting = false;
            }
        }
    }
    void Start()
    {
        inputStates = new Queue<CharacterInput.InputState>();

        cameraMouseAim = Camera.main.GetComponent<CameraMouseAim>();
        cameraAimPoint = Camera.main.GetComponent<CameraAimPoint>();

        characterInput = GetComponent<CharacterInput>();
        characterMovement = GetComponent<CharacterMovement>();
        characterRotation = GetComponent<CharacterRotation>();
    }
 void Awake()
 {
     input = GetComponent<CharacterInput>();
     controller = GetComponent<CharacterFixedController>();
     lookDirection = transform.forward;
 }
    void Start()
    {
        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
        foreach(GameObject player in players) {
            _characterInput = player.GetComponent<CharacterInput>();
            if(_characterInput != null)
                break;
        }

        setSound( PlayerPrefs.GetInt ("soundEnabled", 1) == 1);
        setMusic( PlayerPrefs.GetInt ("musicEnabled", 1) == 1);
        setMouseInvert( PlayerPrefs.GetInt ("mouseInvert", 0) == 1);

        setMouseSensitivity(
            PlayerPrefs.GetFloat("mouseSensitivityX", 5),
            PlayerPrefs.GetFloat("mouseSensitivityY", 5)
            );
    }
 void Awake()
 {
     input = GetComponent<CharacterInput>();
 }
Example #37
0
    void Start()
    {
        if (Network.isClient) {
            clientManager = ClientManager.Get();
            clientManager.characterList.Add(this);
        }
        else {
            serverManager = ServerManager.Get();
            serverManager.characterList.Add(this);
        }

        if (Network.isServer || (Network.isClient && isNotMine)) {
            charCamera.gameObject.SetActive(false);
        }

        input = new CharacterInput(this);
        controller = new CharacterController(this);
        arrows = new CharacterArrows(this);
        fsm = new CharacterFsm(this);
    }