Ejemplo n.º 1
0
    /// <summary>
    /// Update is called once per frame.
    /// </summary>
    void Update()
    {
        if (animator && gamecam.CamState != ThirdPersonCamera.CamStates.FirstPerson)
        {
            stateInfo = animator.GetCurrentAnimatorStateInfo(0);
            transInfo = animator.GetAnimatorTransitionInfo(0);

            // Press A to jump
            if (Input.GetButton("Jump"))
            {
                animator.SetBool("Jump", true);
            }
            else
            {
                animator.SetBool("Jump", false);
            }

            // Pull values from controller/keyboard
            leftX = Input.GetAxis("Horizontal");
            leftY = Input.GetAxis("Vertical");

            charAngle = 0f;
            direction = 0f;
            float charSpeed = 0f;

            // Translate controls stick coordinates into world/cam/character space
            StickToWorldspace(this.transform, gamecam.transform, ref direction, ref charSpeed, ref charAngle, IsInPivot());

            // Press B to sprint
            if (Input.GetButton("Sprint"))
            {
                speed = Mathf.Lerp(speed, SPRINT_SPEED, Time.deltaTime);
                gamecam.GetComponent <Camera>().fieldOfView = Mathf.Lerp(gamecam.GetComponent <Camera>().fieldOfView, SPRINT_FOV, fovDampTime * Time.deltaTime);
            }
            else
            {
                speed = charSpeed;
                gamecam.GetComponent <Camera>().fieldOfView = Mathf.Lerp(gamecam.GetComponent <Camera>().fieldOfView, NORMAL_FOV, fovDampTime * Time.deltaTime);
            }

            animator.SetFloat("Speed", speed, speedDampTime, Time.deltaTime);
            animator.SetFloat("Direction", direction, directionDampTime, Time.deltaTime);

            if (speed > LocomotionThreshold)                    // DEAD zone
            {
                if (!IsInPivot())
                {
                    Animator.SetFloat("Angle", charAngle);
                }
            }
            if (speed < LocomotionThreshold && Mathf.Abs(leftX) < 0.05f)                // DEAD zone
            {
                animator.SetFloat("Direction", 0f);
                animator.SetFloat("Angle", 0f);
            }
        }
    }
Ejemplo n.º 2
0
 private void SetCam(int cam)
 {
     if (cam == 0)
     {
         thisCam.enabled = false;
         tpCam.GetComponent <Camera>().enabled = true;
         tpCam.CanFollow = true;
     }
     else
     {
         thisCam.enabled = true;
         tpCam.GetComponent <Camera>().enabled = false;
         tpCam.CanFollow = false;
     }
 }
Ejemplo n.º 3
0
    private void OnPlayerSetup(SocketIOEvent evt)
    {
        Debug.Log("creating character/controller");

        CharacterType PlayType = (CharacterType)JsonToInt(evt.data.GetField("type").ToString(), "\"");

        bool isSimulated = false;

        Debug.Log("Creating players controller and character:" + PlayType);

        if (PlayType == CharacterType.Blender)         // case blender
        {
            GameObject prefab = Instantiate(BlenderControllerPrefab);
            PlayerBlenderController = prefab.GetComponent <BlenderController> ();
            PlayerBlenderController.CharacterObject = CreateCharacter(evt, isSimulated, BlenderPrefab) as Blender;
            Debug.Log("Created Blender:" + PlayerBlenderController.CharacterObject);
            Blenders.Add(PlayerBlenderController.CharacterObject);

            // for blender 3rd person cam
            GameObject cam = Instantiate(ThirdCam, PlayerBlenderController.CharacterObject.transform.position + ThirdCam.transform.position, ThirdCam.transform.rotation);

            ThirdCamComp = cam.GetComponent <ThirdPersonCamera> ();
            ThirdCamComp.gameObject.SetActive(true);
            ThirdCamComp.GetComponent <ThirdPersonCamera>().Setup(PlayerBlenderController.CharacterObject.gameObject);
            ThirdCamComp.BlenderCamStick = PlayerBlenderController.JoystickCam;
        }
        else if (PlayType == CharacterType.Killer)
        {
            GameObject prefab = Instantiate(KillerControllerPrefab);
            PlayerKillerController = prefab.GetComponent <KillerController> ();
            PlayerKillerController.CharacterObject = CreateCharacter(evt, isSimulated, KillerPrefab) as Killer;
            Debug.Log("Created Killer:" + PlayerKillerController.CharacterObject);
            Killers.Add(PlayerKillerController.CharacterObject);

            // for killer 1st person cam
            GameObject cam = Instantiate(FirstCam);
            FirstCamComp = cam.GetComponent <FirstPersonCamera> ();
            FirstCamComp.gameObject.SetActive(true);
            FirstCamComp.gameObject.transform.position = PlayerKillerController.CharacterObject.HeadTransform.position;
            FirstCamComp.gameObject.transform.parent   = PlayerKillerController.CharacterObject.HeadTransform;
        }

        SocketIOComp.Emit("SERVER:CREATE_FOR_OTHERPLAYER");

        // create NPC blenders
        if (GlobalGameState.IsNPCBlenderMaster)
        {
            GlobalMapManager.CreateNPCBlenders(NPCCount);
        }
    }
Ejemplo n.º 4
0
    public override void Init(object context = null, Action callback = null)
    {
        if (_instance == null)
        {
            _instance      = this;
            _entities      = new List <Entity>();
            _combatEvents  = new List <CombatEvent>();
            _actorsInScene = new List <Actor>(Object.FindObjectsOfType <Actor>());
            MainCamera     = gameCamera.GetComponent <Camera>();
            gameCamera.Init();
        }

        if (context is Actor actor)
        {
            _actorIndex = _actorsInScene.IndexOf(actor);
            SetPlayer(actor, true);
        }

        SetPhysicsPaused(_cachedPhysicsPaused);
        callback?.Invoke();
    }