public void Initialize() { SelectedPC = GameObject.Find("HumanCharacter").GetComponent<HumanCharacter>(); SelectedPC.Initialize(); _numberOfRocks = 10; InputEventHandler.OnCameraSwitchMode += SwitchCameraMode; InputEventHandler.OnPlayerMove += this.OnPlayerMove; InputEventHandler.OnPlayerStopMove += this.OnPlayerStopMove; InputEventHandler.OnWeaponPullTrigger += this.OnWeaponPullTrigger; InputEventHandler.OnWeaponReleaseTrigger += this.OnWeaponReleaseTrigger; InputEventHandler.OnWeaponAim += this.OnWeaponAim; InputEventHandler.OnWeaponStopAim += this.OnWeaponStopAim; InputEventHandler.OnKick += this.OnKick; InputEventHandler.OnPlayerMoveLeft += this.OnPlayerMoveLeft; InputEventHandler.OnPlayerMoveRight += this.OnPlayerMoveRight; InputEventHandler.OnPlayerMoveUp += this.OnPlayerMoveUp; InputEventHandler.OnPlayerMoveDown += this.OnPlayerMoveDown; InputEventHandler.OnPlayerStopMoveLeft += this.OnPlayerStopMoveLeft; InputEventHandler.OnPlayerStopMoveRight += this.OnPlayerStopMoveRight; InputEventHandler.OnPlayerStopMoveUp += this.OnPlayerStopMoveUp; InputEventHandler.OnPlayerStopMoveDown += this.OnPlayerStopMoveDown; InputEventHandler.OnPlayerStartSprint += this.OnPlayerStartSprint; InputEventHandler.OnPlayerStopSprint += this.OnPlayerStopSprint; InputEventHandler.OnPlayerToggleSneak += OnToggleSneaking; InputEventHandler.OnPlayerThrow += OnThrow; InputEventHandler.OnPlayerSwitchWeapon2 += OnToggleWeapon2; InputEventHandler.OnPlayerSwitchWeapon1 += OnToggleWeapon1; InputEventHandler.OnPlayerReload += OnWeaponReload; _moveDirection = PlayerMoveDirEnum.Stop; _moveDirection2 = PlayerMoveDirEnum.Stop; SelectedPC.CurrentStance = HumanStances.Run; }
public void OnPlayerMoveLeft() { if(GameManager.Inst.CameraController.GetCameraMode() == CameraModeEnum.Leader) { if(_moveDirection == PlayerMoveDirEnum.Stop) { _moveDirection = PlayerMoveDirEnum.Left; } else if(_moveDirection2 == PlayerMoveDirEnum.Stop) { _moveDirection2 = PlayerMoveDirEnum.Left; } } }
private void UpdatePlayerMovement() { HumanCharacter c = SelectedPC.GetComponent<HumanCharacter>(); if(_moveDirection != PlayerMoveDirEnum.Stop || _moveDirection2 != PlayerMoveDirEnum.Stop) { float straightDist = Vector3.Distance(SelectedPC.Destination.Value, SelectedPC.transform.position); //Debug.Log("straight dist " + straightDist + " remaining dest " + SelectedPC.MyNavAgent.remainingDistance); if(straightDist < 2 && SelectedPC.MyNavAgent.remainingDistance > straightDist + 1) { _moveDirection = PlayerMoveDirEnum.Stop; _moveDirection2 = PlayerMoveDirEnum.Stop; SelectedPC.SendCommand(CharacterCommands.Idle); } } if((_moveDirection == PlayerMoveDirEnum.Left && _moveDirection2 == PlayerMoveDirEnum.Stop) || (_moveDirection == PlayerMoveDirEnum.Stop && _moveDirection2 == PlayerMoveDirEnum.Left)) { Vector3 roughDest = SelectedPC.transform.position + Camera.main.transform.right * -1 * 1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Left && _moveDirection2 == PlayerMoveDirEnum.Up) || (_moveDirection == PlayerMoveDirEnum.Up && _moveDirection2 == PlayerMoveDirEnum.Left)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + (Camera.main.transform.right * -1 + cameraForwardFlat.normalized).normalized * 1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Left && _moveDirection2 == PlayerMoveDirEnum.Down) || (_moveDirection == PlayerMoveDirEnum.Down && _moveDirection2 == PlayerMoveDirEnum.Left)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + (Camera.main.transform.right * -1 + cameraForwardFlat.normalized * -1).normalized * 1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Right && _moveDirection2 == PlayerMoveDirEnum.Stop) || (_moveDirection == PlayerMoveDirEnum.Stop && _moveDirection2 == PlayerMoveDirEnum.Right)) { Vector3 roughDest = SelectedPC.transform.position + Camera.main.transform.right * 1f; //SelectedPC.Destination = SelectedPC.transform.position + SelectedPC.transform.right * 0.1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Right && _moveDirection2 == PlayerMoveDirEnum.Up) || (_moveDirection == PlayerMoveDirEnum.Up && _moveDirection2 == PlayerMoveDirEnum.Right)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + (Camera.main.transform.right + cameraForwardFlat.normalized).normalized * 1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Right && _moveDirection2 == PlayerMoveDirEnum.Down) || (_moveDirection == PlayerMoveDirEnum.Down && _moveDirection2 == PlayerMoveDirEnum.Right)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + (Camera.main.transform.right + cameraForwardFlat.normalized * -1).normalized * 1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Up && _moveDirection2 == PlayerMoveDirEnum.Stop) || (_moveDirection == PlayerMoveDirEnum.Stop && _moveDirection2 == PlayerMoveDirEnum.Up)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + cameraForwardFlat * 2f; //SelectedPC.Destination = SelectedPC.transform.position + SelectedPC.transform.forward * 0.1f; MakeStep(roughDest); } else if((_moveDirection == PlayerMoveDirEnum.Down && _moveDirection2 == PlayerMoveDirEnum.Stop) || (_moveDirection == PlayerMoveDirEnum.Stop && _moveDirection2 == PlayerMoveDirEnum.Down)) { Vector3 cameraForwardFlat = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 roughDest = SelectedPC.transform.position + cameraForwardFlat * -1 * 2f; //SelectedPC.Destination = SelectedPC.transform.position + SelectedPC.transform.forward * -1 * 0.1f; MakeStep(roughDest); } if(_moveDirection == PlayerMoveDirEnum.Stop && _moveDirection2 == PlayerMoveDirEnum.Stop) { if(_isMoveKeyDown) { //keep updating move direction as the vector from character to mouse cursor's projection point with magnitude of 1 Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Vector3.Distance(c.transform.position, Camera.main.transform.position))); c.Destination = c.transform.position + (mouseWorldPos - c.transform.position).normalized * 2; /* RaycastHit hitMove; Ray rayMove = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, out hit)) { c.Destination = hit.point;// + new Vector3(0, 1, 0); //Debug.Log(c.Destination); } */ } /* Vector3 displacement = c.Destination.Value - c.transform.position; if(displacement.magnitude < 0.1f && !_isMoveKeyDown) { c.SendCommand(CharacterCommands.Idle); //c.GetComponent<CharacterController>().Move(Vector3.zero); } */ } float aimHeight = 0f; if(_aimedObject != null && _aimedObject.tag == "GroundOrFloor") { if(c.CurrentStance == HumanStances.Crouch || c.CurrentStance == HumanStances.CrouchRun) { aimHeight = 1f; } else { aimHeight = 1.5f; } } else { aimHeight = 0; } if(Mathf.Abs(c.AimPoint.y - c.transform.position.y) > 0.5f) { aimHeight = 0; } if(c.UpperBodyState == HumanUpperBodyStates.Aim || c.UpperBodyState == HumanUpperBodyStates.HalfAim || c.UpperBodyState == HumanUpperBodyStates.Idle) { if(c.MyReference.CurrentWeapon != null) { //c.AimTarget.position = Vector3.Lerp(c.AimTarget.position, c.AimPoint + new Vector3(0, aimHeight, 0), 5 * Time.deltaTime); c.AimTargetRoot.position = c.MyReference.CurrentWeapon.transform.position; Vector3 cameraDir = (GameManager.Inst.CameraController.transform.position - c.AimPoint).normalized; Vector3 aimPoint = c.AimPoint + cameraDir * aimHeight; Weapon weapon = c.MyReference.CurrentWeapon.GetComponent<Weapon>(); if(c.MyAI.BlackBoard.TargetEnemy != null && !weapon.IsScoped) { aimPoint = c.MyAI.TargetingSystem.GetAimPointOnTarget(c.MyAI.BlackBoard.TargetEnemy); } else if(weapon.IsScoped) { aimPoint = c.AimPoint; } c.MyAI.BlackBoard.AimPoint = aimPoint; Vector3 aimDir = aimPoint - c.MyReference.CurrentWeapon.transform.position; Quaternion rotation = Quaternion.LookRotation(aimDir); c.AimTargetRoot.transform.rotation = Quaternion.Lerp(c.AimTargetRoot.transform.rotation, rotation, Time.deltaTime * 6); } else { c.AimTargetRoot.position = c.transform.position + Vector3.up * 1.5f; Vector3 cameraDir = (GameManager.Inst.CameraController.transform.position - c.AimPoint).normalized; Vector3 aimPoint = c.AimPoint + cameraDir; Vector3 aimDir = aimPoint - c.AimTargetRoot.position;//c.transform.position; Quaternion rotation = Quaternion.LookRotation(aimDir); c.AimTargetRoot.transform.rotation = Quaternion.Lerp(c.AimTargetRoot.transform.rotation, rotation, Time.deltaTime * 6); } Vector3 lookPosition; if(SelectedPC.MyReference.Flashlight.IsOn) { lookPosition = c.AimTarget.position; } else { lookPosition = new Vector3(c.AimTarget.position.x, c.transform.position.y + 1.5f, c.AimTarget.position.z); } c.LookTarget.position = Vector3.Lerp(c.LookTarget.position, lookPosition, 10 * Time.deltaTime); } }
public void Initialize() { Party = new PlayerParty(this); Party.Initialize(); TimedAction = new PlayerTimedAction(this); _vignette = Camera.main.GetComponent<VignetteAndChromaticAberration>(); IsHoldToAim = true; _numberOfRocks = 10; InputEventHandler.OnCameraSwitchMode += SwitchCameraMode; InputEventHandler.OnPlayerMove += this.OnPlayerMove; InputEventHandler.OnPlayerStopMove += this.OnPlayerStopMove; InputEventHandler.OnWeaponPullTrigger += this.OnWeaponPullTrigger; InputEventHandler.OnWeaponReleaseTrigger += this.OnWeaponReleaseTrigger; InputEventHandler.OnRMBDown += this.OnRMBDown; InputEventHandler.OnRMBUp += this.OnRMBUp; InputEventHandler.OnLRMBDown += this.OnLRMBDown; InputEventHandler.OnKick += this.OnKick; InputEventHandler.OnPlayerMoveLeft += this.OnPlayerMoveLeft; InputEventHandler.OnPlayerMoveRight += this.OnPlayerMoveRight; InputEventHandler.OnPlayerMoveUp += this.OnPlayerMoveUp; InputEventHandler.OnPlayerMoveDown += this.OnPlayerMoveDown; InputEventHandler.OnPlayerStopMoveLeft += this.OnPlayerStopMoveLeft; InputEventHandler.OnPlayerStopMoveRight += this.OnPlayerStopMoveRight; InputEventHandler.OnPlayerStopMoveUp += this.OnPlayerStopMoveUp; InputEventHandler.OnPlayerStopMoveDown += this.OnPlayerStopMoveDown; InputEventHandler.OnPlayerStartSprint += this.OnPlayerStartSprint; InputEventHandler.OnPlayerStopSprint += this.OnPlayerStopSprint; InputEventHandler.OnPlayerToggleSneak += OnToggleSneaking; InputEventHandler.OnPlayerThrow += OnThrow; InputEventHandler.OnPlayerSwitchWeapon2 += OnToggleWeapon2; InputEventHandler.OnPlayerSwitchWeapon1 += OnToggleWeapon1; InputEventHandler.OnPlayerSwitchThrown += OnToggleThrown; InputEventHandler.OnPlayerSwitchTool += OnToggleTool; InputEventHandler.OnPlayerReload += OnWeaponReload; InputEventHandler.OnToggleFlashlight += OnToggleFlashlight; InputEventHandler.OnGameTogglePause += ToggleGamePause; InputEventHandler.OnSelectMember1 += OnSelectMember1; InputEventHandler.OnSelectMember2 += OnSelectMember2; InputEventHandler.OnSelectMember3 += OnSelectMember3; InputEventHandler.OnSelectMember4 += OnSelectMember4; InputEventHandler.OnMouseSelect += OnPlayerMouseSelect; InputEventHandler.OnClearTask += OnClearTask; _moveDirection = PlayerMoveDirEnum.Stop; _moveDirection2 = PlayerMoveDirEnum.Stop; SelectedPC.CurrentStance = HumanStances.Run; _playerLight = GameObject.Find("PlayerLight").GetComponent<Light>(); _playerLight.intensity = 0.1f; }