public static void UpdateTransform(PlayerEntity player, float deltaTime) { var parent = player.RootGo().transform; var child = player.thirdPersonModel.Value.transform; var pos = child.localPosition - ModelInitPosition; var rotation = child.localRotation; parent.Translate(Vector3.right * pos.x); parent.Translate(Vector3.up * pos.y); parent.Translate(Vector3.forward * pos.z); parent.rotation = player.orientation.RotationYaw; parent.rotation *= rotation; var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4(); var currentVelocity = player.orientation.RotationYaw * player.stateInterface.State.GetSpeed(lastVel, deltaTime); currentVelocity.y = 0; player.characterContoller.Value.Move(currentVelocity * deltaTime); child.localPosition = ModelInitPosition; child.localRotation = Quaternion.identity; player.playerMoveByAnimUpdate.NeedUpdate = true; player.position.Value = parent.position; player.playerMoveByAnimUpdate.Position = parent.position.ShiftedToFixedVector3(); player.playerMoveByAnimUpdate.ModelPitch = player.orientation.ModelPitch = YawPitchUtility.Normalize(parent.rotation.eulerAngles.x); player.playerMoveByAnimUpdate.ModelYaw = player.orientation.ModelYaw = YawPitchUtility.Normalize(parent.rotation.eulerAngles.y); }
public void Generate(PlayerEntity player, IUserCmd usercmd, float archorYaw, float archorPitch) { DeltaYaw = usercmd.DeltaYaw; DeltaPitch = usercmd.DeltaPitch; if (usercmd.FilteredInput != null) { IsCameraFree = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree); FilteredChangeCamera = usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera); FilteredCameraFocus = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus); } FrameInterval = usercmd.FrameInterval; ChangeCamera = usercmd.ChangeCamera; IsCameraFocus = usercmd.IsCameraFocus; IsCmdRun = usercmd.IsRun; IsCmdMoveVertical = usercmd.MoveVertical > 0; CurrentPostureState = player.stateInterface.State.GetCurrentPostureState(); NextPostureState = player.stateInterface.State.GetNextPostureState(); LeanState = player.stateInterface.State.GetNextLeanState(); IsAirPlane = player.gamePlay.GameState == GameState.AirPlane; ActionState = player.stateInterface.State.GetActionState(); ActionKeepState = player.stateInterface.State.GetActionKeepState(); IsDriveCar = player.IsOnVehicle(); IsDead = player.gamePlay.IsLifeState(EPlayerLifeState.Dead); CanWeaponGunSight = player.hasBag && player.GetBagLogicImp().GetCurrentWeaponInfo().Id >= 1 & player.weaponLogic.State.CanCameraFocus(); ArchorPitch = YawPitchUtility.Normalize(archorPitch); ArchorYaw = YawPitchUtility.Normalize(archorYaw); IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached; ForceChangeGunSight = player.playerWeaponState.ForceChangeGunSight; ForceInterruptGunSight = UseActionOrIsStateNoGunSight(usercmd, player); player.playerWeaponState.ForceChangeGunSight = false; }
public virtual void SetCharacterRotation(Vector3 euler) { if (!CompareUtility.IsApproximatelyEqual(YawPitchUtility.Normalize(_motor.TransientRotation.eulerAngles), euler, EPS)) { _motor.SetRotation(Quaternion.Euler(euler)); } }
public void FakeForObserve(PlayerEntity player) { IsDead = player.gamePlay.IsLifeState(EPlayerLifeState.Dead); ArchorPitch = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.x); ArchorYaw = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.y); RoleId = player.playerInfo.RoleModelId; }
public override void UpdatePlayerRotation(ICameraMotorInput input, ICameraMotorState state, PlayerEntity player) { if (!input.IsDead && CanRotatePlayer(state)) { float newDeltaAngle = input.DeltaYaw; if (player.playerRotateLimit.LimitAngle) { var candidateAngle = YawPitchUtility.Normalize(player.orientation.Yaw) + input.DeltaYaw; candidateAngle = Mathf.Clamp(candidateAngle, player.playerRotateLimit.LeftBound, player.playerRotateLimit.RightBound); player.orientation.Yaw = CalculateFrameVal(candidateAngle, 0f, _config.YawLimit); } else { player.orientation.Yaw = CalculateFrameVal(player.orientation.Yaw, newDeltaAngle, _config.YawLimit); } // newDeltaAngle = player.characterContoller.Value.PreRotateAngle(player.orientation.ModelView, player.position.Value,input.DeltaYaw, input.FrameInterval * 0.001f); // Logger.DebugFormat("deltaAngle:{0},prevAngle:{1}, curYaw:{2}, input.DeltaYaw:{4},player.orientationLimit.LimitAngle:{5}", // newDeltaAngle, // player.orientation.Yaw, // CalculateFrameVal(player.orientation.Yaw, newDeltaAngle, _config.YawLimit), // input.DeltaYaw // ); var deltaPitch = HandlePunchPitch(player, input); player.orientation.Pitch = CalculateFrameVal(player.orientation.Pitch, deltaPitch, _config.PitchLimit); } }
public static void Move(Contexts contexts, PlayerEntity player, float deltaTime) { var state = player.stateInterface.State; var postureInConfig = state.GetNextPostureState(); var controller = player.characterContoller.Value; controller.SetCurrentControllerType(postureInConfig); var diveXAngle = CalcDiveXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue); controller.SetCharacterPosition(player.position.Value); //_logger.InfoFormat("my epxected rot:x:{0},y:{1}, new:{2}", diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw),YawPitchUtility.Normalize(Quaternion.Euler(diveXAngle,YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0 )).ToStringExt() ); controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0)); var velocity = player.stateInterface.State.GetSpeed(Vector3.zero, deltaTime); velocity = player.orientation.RotationView * velocity.ToVector4(); var velocityOffset = player.stateInterface.State.GetSpeedOffset(); var dist = (velocity + velocityOffset) * deltaTime; PlayerMoveUtility.Move(contexts, player, player.characterContoller.Value, dist, deltaTime); //_logger.InfoFormat("dive move dist:{0}, prev pos:{1}, after pos:{2}", dist.ToStringExt(), player.position.Value.ToStringExt(), controller.transform.position.ToStringExt()); player.playerMove.Velocity = velocity; player.position.Value = controller.transform.position; }
public static void UpdateTransform(PlayerEntity player, float deltaTime) { var parent = player.RootGo().transform; var child = player.thirdPersonModel.Value.transform; var pos = child.localPosition - ModelInitPosition; var rotation = child.localRotation; parent.Translate(Vector3.right * pos.x); parent.Translate(Vector3.up * pos.y); parent.Translate(Vector3.forward * pos.z); parent.rotation *= rotation; child.localPosition = ModelInitPosition; child.localRotation = Quaternion.identity; player.playerMoveByAnimUpdate.NeedUpdate = true; player.position.Value = parent.position; player.playerMoveByAnimUpdate.Position = parent.position.ShiftedToFixedVector3(); player.playerMoveByAnimUpdate.ModelPitch = player.orientation.ModelPitch = YawPitchUtility.Normalize(parent.rotation.eulerAngles.x); player.playerMoveByAnimUpdate.ModelYaw = player.orientation.ModelYaw = YawPitchUtility.Normalize(parent.rotation.eulerAngles.y); if (player.hasPlayerMove) { player.playerMove.Velocity = Vector3.zero; } if (player.hasMoveUpdate) { player.moveUpdate.Velocity = Vector3.zero; } }
public void Update(CodeRigBoneParam param) { param.PeekAmplitude = PeekDegree; param.SightProgress = _sightProgress; param.FastMoveHorizontalShift = _fastMoveHorizontalShift; param.FastMoveVerticalShift = _fastMoveVerticalShift; param.SightMoveHorizontalShift = _sightMoveHorizontalShift; param.SightMoveVerticalShift = _sightMoveVerticalShift; param.IsFirstPerson = IsFirstPerson; var needIk = UpdateSightData(ref param); // 有动作状态控制是否需要开启IK param.IKActive = IsIKActive || param.IKActive && needIk; param.IsEmptyHand = _weaponController.IsEmptyHand(); if (param.IsEmptyHand) { if (!IsFirstPerson) { //第三人称空手取消pitch param.PitchAmplitude = 0; } // 空手状态没有随动效果 param.FastMoveHorizontalShift = 0; param.FastMoveVerticalShift = 0; _attachmentNeedIK = false; } param.SightModelOffset = YawPitchUtility.Normalize(_characterRoot.transform.rotation).x; _boneRigging.Update(param); _followRot.Update(param); UpdateIk(); }
private void UpdateTransform(PlayerEntity player) { //rootMotion控制人物移动 if (!player.thirdPersonAnimator.UnityAnimator.applyRootMotion) { player.playerMoveByAnimUpdate.NeedUpdate = false; return; } var parent = player.RootGo().transform; var child = player.thirdPersonModel.Value.transform; parent.Translate(Vector3.right * child.localPosition.x); parent.Translate(Vector3.up * child.localPosition.y); parent.Translate(Vector3.forward * child.localPosition.z); child.localPosition = Vector3.zero; child.localRotation = Quaternion.identity; player.playerMoveByAnimUpdate.NeedUpdate = true; player.playerMoveByAnimUpdate.Position = player.position.Value = parent.position; player.playerMoveByAnimUpdate.ModelPitch = player.orientation.ModelPitch = YawPitchUtility.Normalize(parent.rotation.eulerAngles.x); player.playerMoveByAnimUpdate.ModelYaw = player.orientation.ModelYaw = YawPitchUtility.Normalize(parent.rotation.eulerAngles.y); if (player.hasPlayerMove) { player.playerMove.Velocity = Vector3.zero; } if (player.hasMoveUpdate) { player.moveUpdate.Velocity = Vector3.zero; } }
protected static float CalculateFrameVal(float angle, float delta, ViewLimit limit) { angle = YawPitchUtility.Normalize(angle); return(limit.Flag && (limit.Min > -180f || limit.Max < 180f) ? Mathf.Clamp(angle + delta, limit.Min, limit.Max) : (angle + delta)); }
private void SyncPoseToComponent(PlayerEntity player) { var syncTransform = player.RootGo().transform; player.position.Value = syncTransform.position; var angles = syncTransform.eulerAngles; player.orientation.Yaw = YawPitchUtility.Normalize(angles.y); }
private static void UpdatePlayerComponent(PlayerEntity player) { player.stateInterface.State.SetMoveInWater(SpeedCalculator.IsLimitSpeedInWater); player.playerMove.Velocity = SpeedCalculator.CurrentVelocity; var syncTransform = player.RootGo().transform; player.position.Value = syncTransform.position; player.orientation.ModelPitch = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.x); player.orientation.ModelYaw = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.y); }
private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera, Vector3 punchRotation, PlayerEntity player, int curTime) { var doLag = !player.appearanceInterface.Appearance.IsFirstPerson; var realRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation); var postOffset = calsOut.ArchorPostOffset + calsOut.PostOffset; var realArchorOffset = calsOut.ArchorOffset; var realPostOffset = postOffset; var archorRotation = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0); //计算头顶位置 _archoroffsetArm.Offset = realArchorOffset / 2; var heightTestStart = calsOut.ArchorPosition + archorRotation * realArchorOffset / 2; _archoroffsetArm.Update(heightTestStart, archorRotation, curTime - LastTime, doLag, calsOut.NeedDetectDistance); realArchorOffset = _archoroffsetArm.LastLoc - calsOut.ArchorPosition; //计算锚点位置 _postOffsetArm.Offset = realPostOffset; _postOffsetArm.Update(_archoroffsetArm.LastLoc, archorRotation, curTime - LastTime, false, calsOut.NeedDetectDistance); realPostOffset = _postOffsetArm.LastLoc - _archoroffsetArm.LastLoc; var postOffsetFactor = Mathf.Max(realPostOffset.magnitude / postOffset.magnitude, 1); var startingPosition = calsOut.FinalArchorPosition = calsOut.ArchorPosition + postOffsetFactor * realArchorOffset + realPostOffset; //封闭建筑内拉近摄像机距离 // if(BuildingRestrictTest(calsOut, player)) // calsOut.Offset = calsOut.Offset.normalized * OffsetInBuilding; //相机位置计算 _offsetArm.Offset = calsOut.Offset; _offsetArm.Update(startingPosition, realRotation, curTime - LastTime, doLag, true); camera.PlayerFocusPosition = startingPosition; camera.Position = _offsetArm.LastLoc; camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation; camera.EulerAngle.x = YawPitchUtility.Normalize(camera.EulerAngle.x); camera.EulerAngle.y = YawPitchUtility.Normalize(camera.EulerAngle.y); camera.EulerAngle.z = YawPitchUtility.Normalize(camera.EulerAngle.z); camera.Fov = calsOut.Fov; camera.Far = calsOut.Far; camera.Near = calsOut.Near; #if UNITY_EDITOR var p1 = calsOut.ArchorPosition; var p2 = _archoroffsetArm.LastLoc; var p3 = startingPosition; var p4 = _offsetArm.LastLoc; Debug.DrawLine(p1, p2, Color.red); Debug.DrawLine(p2, p3, Color.green); Debug.DrawLine(p3, p4, Color.blue); #endif }
protected virtual void SyncPoseToComponent(PlayerEntity player) { var syncTransform = player.RootGo().transform; player.position.Value = syncTransform.position; var angles = syncTransform.eulerAngles; player.orientation.Pitch = YawPitchUtility.Normalize(angles.x); player.orientation.Yaw = YawPitchUtility.Normalize(angles.y); player.orientation.Roll = YawPitchUtility.Normalize(angles.z); }
public DrivePoseMotor(ECameraPoseMode modeId, HashSet <ECameraPoseMode> excludes, VehicleContext vehicleContext, FreeMoveContext freeMoveContext, Motors m ) : base(m) { _modeId = (short)modeId; _motors = m; this.excludes = new HashSet <short>(); foreach (var e in excludes) { this.excludes.Add((short)e); } _order = SingletonManager.Get <CameraConfigManager>().GetRoleConfig() .GetCameraConfigItem((ECameraPoseMode)_modeId).Order; _motors.ActionManager.AddAction(CameraActionType.Enter, SubCameraMotorType.Pose, (int)modeId, (player, state) => { if (player.IsOnVehicle()) { var vehicle = vehicleContext.GetEntityWithEntityKey(player.controlledVehicle.EntityKey); player.controlledVehicle.CameraAnchorOffset = vehicle.vehicleAssetInfo.CameraAnchorOffset; player.controlledVehicle.CameraDistance = vehicle.vehicleAssetInfo.CameraDistance; player.controlledVehicle.CameraRotationDamping = vehicle.vehicleAssetInfo.CameraRotationDamping; } var cameraEulerAngle = player.cameraFinalOutputNew.EulerAngle; var carEulerAngle = player.cameraArchor.ArchorEulerAngle; var t = cameraEulerAngle - carEulerAngle; state.FreeYaw = t.y; state.FreePitch = t.x; }); _motors.ActionManager.AddAction(CameraActionType.Leave, SubCameraMotorType.Pose, (int)modeId, (player, state) => { var rotation = player.cameraFinalOutputNew.EulerAngle; player.orientation.Yaw = YawPitchUtility.Normalize(rotation.y); player.orientation.Pitch = YawPitchUtility.Normalize(rotation.x); state.LastFreePitch = 0; state.LastFreeYaw = 0; state.FreeYaw = 0f; state.FreePitch = 0f; }); }
private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera, Vector3 punchRotation, PlayerEntity player, bool doLag, int curTime) { var realRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation); var index = (player.gamePlay.JobAttribute == (int)EJobAttribute.EJob_Variant) ? 0.75f : 1f; var postOffset = calsOut.ArchorPostOffset + calsOut.PostOffset; var realArchorOffset = calsOut.ArchorOffset; var realPostOffset = postOffset; var archorRotation = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0); //计算头顶位置 _archoroffsetArm.Offset = realArchorOffset / 2 * index; var heightTestStart = calsOut.ArchorPosition + archorRotation * realArchorOffset / 2 * index; _archoroffsetArm.Update(heightTestStart, archorRotation, curTime - LastTime, doLag, calsOut.NeedDetectDistance); realArchorOffset = (_archoroffsetArm.LastLoc - calsOut.ArchorPosition); //计算锚点位置 _postOffsetArm.Offset = realPostOffset * index; _postOffsetArm.Update(_archoroffsetArm.LastLoc, archorRotation, curTime - LastTime, false, calsOut.NeedDetectDistance); realPostOffset = (_postOffsetArm.LastLoc - _archoroffsetArm.LastLoc); var postOffsetFactor = Mathf.Max(realPostOffset.magnitude / postOffset.magnitude, 1); var startingPosition = calsOut.FinalArchorPosition = calsOut.ArchorPosition + postOffsetFactor * realArchorOffset + realPostOffset; //相机位置计算 _offsetArm.Offset = calsOut.Offset * index; _offsetArm.Update(startingPosition, realRotation, curTime - LastTime, doLag, true); camera.PlayerFocusPosition = startingPosition; camera.Position = _offsetArm.LastLoc; camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation; camera.EulerAngle.x = YawPitchUtility.Normalize(camera.EulerAngle.x); camera.EulerAngle.y = YawPitchUtility.Normalize(camera.EulerAngle.y); camera.EulerAngle.z = YawPitchUtility.Normalize(camera.EulerAngle.z); camera.Fov = calsOut.Fov; camera.Far = calsOut.Far; camera.Near = calsOut.Near; #if UNITY_EDITOR var p1 = calsOut.ArchorPosition; var p2 = _archoroffsetArm.LastLoc; var p3 = startingPosition; var p4 = _offsetArm.LastLoc; Debug.DrawLine(p1, p2, Color.red); Debug.DrawLine(p2, p3, Color.green); Debug.DrawLine(p3, p4, Color.blue); #endif }
public override void PreProcessInput(PlayerEntity player, ICameraMotorInput input, ICameraMotorState state) { var config = input.GetPoseConfig(state.GetMainMotor().NowMode); float yaw = state.FreeYaw + input.ArchorYaw; float pitch = state.FreePitch + input.ArchorPitch; yaw = CalculateFrameVal(yaw, input.DeltaYaw, config.YawLimit); pitch = CalculateFrameVal(pitch, input.DeltaPitch, config.PitchLimit); state.LastFreeYaw = player.cameraStateNew.FreeYaw; state.LastFreePitch = player.cameraStateNew.FreePitch; state.FreeYaw = YawPitchUtility.Normalize(yaw - input.ArchorYaw); state.FreePitch = YawPitchUtility.Normalize(pitch - input.ArchorPitch); }
public void Generate(PlayerEntity player, IUserCmd usercmd, ICameraMotorState state, bool lockView) { var speedRatio = CameraUtility.GetGunSightSpeed(player, state); DeltaYaw = usercmd.DeltaYaw * speedRatio; DeltaPitch = usercmd.DeltaPitch * speedRatio; if (usercmd.FilteredInput != null) { IsCameraFree = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree); FilteredChangeCamera = lockView ? false : usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera); FilteredCameraFocus = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus); } FrameInterval = usercmd.FrameInterval; ChangeCamera = lockView ? false :usercmd.ChangeCamera; IsCameraFocus = usercmd.IsCameraFocus; IsCmdRun = usercmd.IsRun; IsCmdMoveVertical = usercmd.MoveVertical > 0; InterruptCameraFocus = usercmd.IsUseAction || usercmd.IsTabDown; if (player.hasStateInterface) { CurrentPostureState = player.stateInterface.State.GetCurrentPostureState(); NextPostureState = player.stateInterface.State.GetNextPostureState(); LeanState = player.stateInterface.State.GetNextLeanState(); ActionState = player.stateInterface.State.GetActionState(); ActionKeepState = player.stateInterface.State.GetActionKeepState(); } else if (player.hasThirdPersonAppearance) { CurrentPostureState = (PostureInConfig)player.thirdPersonAppearance.PostureValue; NextPostureState = (PostureInConfig)player.thirdPersonAppearance.NextPostureValue; ActionState = (ActionInConfig)player.thirdPersonAppearance.ActionValue; } IsAirPlane = player.gamePlay.GameState == GameState.AirPlane; IsDriveCar = player.IsOnVehicle(); IsDead = player.gamePlay.IsLifeState(EPlayerLifeState.Dead); CanWeaponGunSight = player.WeaponController().HeldWeaponAgent.CanWeaponSight; ArchorPitch = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.x); ArchorYaw = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.y); IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached; LastViewByOrder = player.gamePlay.LastViewModeByCmd; RoleId = player.playerInfo.RoleModelId; LockViewByRoom = lockView; ModelLoaded = player.hasFirstPersonModel && player.hasThirdPersonModel; IsVariant = JudgeVariant(player); }
private void MoveOnGround(PlayerEntity player, float deltaTime, bool moveInWater) { var state = player.stateInterface.State; var postureInConfig = state.GetNextPostureState(); var controller = player.characterContoller.Value; //旋转包围盒 RotBox(player, deltaTime, postureInConfig, controller); var playerRoot = player.RootGo(); var syncTransform = playerRoot.transform; var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4();; Vector4 velocity = lastVel.ToVector4(); Vector4 velocityOffset = Vector3.zero.ToVector4(); float latestCollisionSlope = 0f; CalculateVelocity(ref velocity, ref velocityOffset, ref latestCollisionSlope, deltaTime, player, moveInWater, controller, lastVel); //坡度计算 if (state.GetCurrentPostureState() == PostureInConfig.Jump && ((int)controller.collisionFlags & (int)UnityEngine.CollisionFlags.Sides) != 0) { JumpSpeedProject(ref velocity, controller); } //_logger.InfoFormat("curVel:{0},VelOffset:{1}", velocity.ToStringExt(), velocityOffset.ToStringExt()); var scaledVel = (velocity); scaledVel.Scale(new Vector4(player.playerMove.MoveSpeedRatio, 1, player.playerMove.MoveSpeedRatio, 1)); var dist = (scaledVel + velocityOffset) * deltaTime; PlayerMoveUtility.Move(_contexts, player, controller, dist, deltaTime); //_logger.InfoFormat("dist:{0}, velocity:{4},velocityOffset:{5} ,flag:{6}, nextCurState:{1}, controllerType:{2}, currentState:{3}", dist.ToStringExt(), postureInConfig, controller.GetCurrentControllerType(),state.GetCurrentPostureState(),velocity, velocityOffset, controller.collisionFlags); //落地或碰到天花板,速度降为0 HandleCollision(ref velocity, player, controller, latestCollisionSlope); //_logger.InfoFormat("v.y:{0}, isGround:{1},latestCollisionSlope:{2}", player.playerMove.Velocity.y, player.playerMove.IsGround, latestCollisionSlope); CalcuSlope(player, syncTransform); player.stateInterface.State.SetMoveInWater(moveInWater); player.playerMove.Velocity = velocity; player.position.Value = syncTransform.position; player.orientation.ModelPitch = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.x); player.orientation.ModelYaw = YawPitchUtility.Normalize(syncTransform.rotation.eulerAngles.y); }
private void SyncPoseToComponent(PlayerEntity player) { var playerSyncTransform = player.RootGo().transform; player.position.Value = playerSyncTransform.position; //_logger.DebugFormat("parachute moveing:{0}", player.position.Value); var angles = playerSyncTransform.eulerAngles; player.orientation.Pitch = YawPitchUtility.Normalize(angles.x); player.orientation.Yaw = YawPitchUtility.Normalize(angles.y); player.orientation.Roll = YawPitchUtility.Normalize(angles.z); var syncTransform = player.playerSkyMove.Parachute.transform; player.playerSkyMove.Position = syncTransform.position; player.playerSkyMove.Rotation = syncTransform.rotation; }
public void Generate(Contexts contexts, PlayerEntity player, IUserCmd usercmd, float archorYaw, float archorPitch, ICameraMotorState state) { var speedRatio = CameraUtility.GetGunSightSpeed(player, state); DeltaYaw = usercmd.DeltaYaw * speedRatio; DeltaPitch = usercmd.DeltaPitch * speedRatio; if (usercmd.FilteredInput != null) { IsCameraFree = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree); FilteredChangeCamera = usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera); FilteredCameraFocus = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus); } var controller = player.WeaponController(); FrameInterval = usercmd.FrameInterval; ChangeCamera = usercmd.ChangeCamera; IsCameraFocus = usercmd.IsCameraFocus; IsCmdRun = usercmd.IsRun; IsCmdMoveVertical = usercmd.MoveVertical > 0; CurrentPostureState = player.stateInterface.State.GetCurrentPostureState(); NextPostureState = player.stateInterface.State.GetNextPostureState(); LeanState = player.stateInterface.State.GetNextLeanState(); IsAirPlane = player.gamePlay.GameState == GameState.AirPlane; ActionState = player.stateInterface.State.GetActionState(); ActionKeepState = player.stateInterface.State.GetActionKeepState(); IsDriveCar = player.IsOnVehicle(); IsDead = player.gamePlay.IsLifeState(EPlayerLifeState.Dead); CanWeaponGunSight = controller.HeldWeaponAgent.CanWeaponSight; ArchorPitch = YawPitchUtility.Normalize(archorPitch); ArchorYaw = YawPitchUtility.Normalize(archorYaw); IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached; if (player.gamePlay.CameraEntityId == 0) { IsObservingFreemove = false; } else { IsObservingFreemove = null != contexts.freeMove.GetEntityWithEntityKey(new EntityKey(player.gamePlay.CameraEntityId, (short)EEntityType.FreeMove)); } InterruptCameraFocus = usercmd.IsUseAction || usercmd.IsTabDown; LastViewByOrder = player.gamePlay.LastViewModeByCmd; }
private void CalcuWhenObserveFreeMove(PlayerEntity playerEntity, FreeMoveEntity observedFreeMove) { var camera = playerEntity.cameraFinalOutputNew; var calsOut = playerEntity.cameraStateOutputNew; camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle; camera.EulerAngle.x = YawPitchUtility.Normalize(camera.EulerAngle.x); camera.EulerAngle.y = YawPitchUtility.Normalize(camera.EulerAngle.y); camera.EulerAngle.z = YawPitchUtility.Normalize(camera.EulerAngle.z); var rotation = Quaternion.Euler(camera.EulerAngle); var archorPos = observedFreeMove.position.Value + observeOffset; float actualDistance = ActualDistance(rotation, archorPos, observeDistance, _collisionLayers); var finalPostOffset = -rotation.Forward() * actualDistance; camera.Position = archorPos + finalPostOffset; Debug.DrawLine(observedFreeMove.position.Value, archorPos, Color.green); Debug.DrawLine(archorPos, camera.Position, Color.blue); }
public static void Move(Contexts contexts, PlayerEntity player, float deltaTime) { var state = player.stateInterface.State; var postureInConfig = state.GetNextPostureState(); var controller = player.characterContoller.Value; controller.SetCurrentControllerType(postureInConfig); controller.SetCharacterPosition(player.position.Value); var diveXAngle = CalcSwimXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue); controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0)); var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4(); var velocity = player.stateInterface.State.GetSpeed(lastVel, deltaTime); velocity = player.orientation.RotationYaw * velocity.ToVector4(); var velocityOffset = player.stateInterface.State.GetSpeedOffset(); var dist = (velocity + velocityOffset) * deltaTime; if (DiveTest(player, velocityOffset, dist)) { player.stateInterface.State.Dive(); DiveHandler.Move(contexts, player, deltaTime); player.moveUpdate.BeginDive = true; } else { PlayerMoveUtility.Move(contexts, player, player.characterContoller.Value, dist, deltaTime); player.playerMove.Velocity = velocity; player.position.Value = controller.transform.position; } }
public override void UpdatePlayerRotation(ICameraMotorInput input, ICameraMotorState state, PlayerEntity player) { if ((!input.IsDead || input.IsDead && player.gamePlay.IsObserving()) && CanRotatePlayer(state)) { float newDeltaAngle = input.DeltaYaw; if (player.playerRotateLimit.LimitAngle) { var candidateAngle = YawPitchUtility.Normalize(player.orientation.Yaw) + input.DeltaYaw; candidateAngle = Mathf.Clamp(candidateAngle, player.playerRotateLimit.LeftBound, player.playerRotateLimit.RightBound); player.orientation.Yaw = CalculateFrameVal(candidateAngle, 0f, input.GetPoseConfig(_modeId).YawLimit); } else { player.orientation.Yaw = CalculateFrameVal(player.orientation.Yaw, newDeltaAngle, input.GetPoseConfig(_modeId).YawLimit); } var deltaPitch = HandlePunchPitch(player, input); player.orientation.Pitch = CalculateFrameVal(player.orientation.Pitch, deltaPitch, input.GetPoseConfig(_modeId).PitchLimit); } }
public void Generate(Contexts contexts, PlayerEntity player, IUserCmd usercmd, float archorYaw, float archorPitch) { DeltaYaw = usercmd.DeltaYaw; DeltaPitch = usercmd.DeltaPitch; if (usercmd.FilteredInput != null) { IsCameraFree = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree); FilteredChangeCamera = usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera); FilteredCameraFocus = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus); } var controller = player.WeaponController(); FrameInterval = usercmd.FrameInterval; ChangeCamera = usercmd.ChangeCamera; IsCameraFocus = usercmd.IsCameraFocus; IsCmdRun = usercmd.IsRun; IsCmdMoveVertical = usercmd.MoveVertical > 0; CurrentPostureState = player.stateInterface.State.GetCurrentPostureState(); NextPostureState = player.stateInterface.State.GetNextPostureState(); LeanState = player.stateInterface.State.GetNextLeanState(); IsAirPlane = player.gamePlay.GameState == GameState.AirPlane; ActionState = player.stateInterface.State.GetActionState(); ActionKeepState = player.stateInterface.State.GetActionKeepState(); IsDriveCar = player.IsOnVehicle(); IsDead = player.gamePlay.IsLifeState(EPlayerLifeState.Dead); CanWeaponGunSight = controller.HeldWeaponAgent.CanWeaponSight; ArchorPitch = YawPitchUtility.Normalize(archorPitch); ArchorYaw = YawPitchUtility.Normalize(archorYaw); IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached; if (!controller.IsHeldSlotEmpty) { ForceChangeGunSight = controller.HeldWeaponAgent.RunTimeComponent.ForceChangeGunSight; } ForceInterruptGunSight = UseActionOrIsStateNoGunSight(usercmd, controller); controller.HeldWeaponAgent.RunTimeComponent.ForceChangeGunSight = false; }
public void ExecuteUserCmd(IPlayerUserCmdGetter getter, IUserCmd cmd) { PlayerEntity playerEntity = getter.OwnerEntity as PlayerEntity; if (!playerEntity.hasCharacterContoller || !playerEntity.hasPlayerRotateLimit || !playerEntity.hasPosition || !playerEntity.hasOrientation) { return; } var controller = playerEntity.characterContoller.Value; var limitComponent = playerEntity.playerRotateLimit; if (controller.enabled && controller.GetCurrentControllerType() == CharacterControllerType.ProneKinematicCharacterController) { var bound = controller.GetRotateBound(playerEntity.orientation.ModelView, playerEntity.position.Value, cmd.FrameInterval); var yaw = YawPitchUtility.Normalize(playerEntity.orientation.ModelYaw); limitComponent.SetLimit(yaw + bound.Key, yaw + bound.Value); //Logger.InfoFormat("seq:{0}, lowerBound:{1}, upperBoound:{2}, cur Yaw:{3}", cmd.Seq ,bound.Key, bound.Value, yaw); } else { limitComponent.SetNoLimit(); } }
private void SwimMove(PlayerEntity player, float deltaTime, IUserCmd cmd) { var state = player.stateInterface.State; var postureInConfig = state.GetNextPostureState(); var controller = player.characterContoller.Value; controller.SetCurrentControllerType(postureInConfig); controller.SetCharacterPosition(player.position.Value); var diveXAngle = CalcSwimXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue); controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0)); var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4(); var velocity = player.stateInterface.State.GetSpeed(lastVel, deltaTime); velocity = player.orientation.RotationYaw * velocity.ToVector4(); var velocityOffset = player.stateInterface.State.GetSpeedOffset(); var dist = (velocity + velocityOffset) * deltaTime; if (velocityOffset.magnitude > 0 || (player.stateInterface.State.IsForth && dist.sqrMagnitude > 0 && player.orientation.Pitch >= (SingletonManager.Get <CameraConfigManager>().GetConfigByType(ECameraConfigType.ThirdPerson).PitchLimit.Max - 1))) { player.stateInterface.State.Dive(); DiveMove(player, deltaTime, cmd); player.moveUpdate.BeginDive = true; } else { PlayerMoveUtility.Move(_contexts, player, player.characterContoller.Value, dist, deltaTime); player.playerMove.Velocity = velocity; player.position.Value = controller.transform.position; } }
public void ExecuteUserCmd(IUserCmdOwner owner, IUserCmd cmd) { if (cmd.IsUseAction && cmd.UseType == (int)EUseActionType.Door) { var door = _context.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(cmd.UseEntityId, (short)EEntityType.MapObject)); if (door == null) { _logger.ErrorFormat("Door Entity {0} does not exist!", cmd.UseEntityId); return; } if (!door.hasDoorRotate && door.doorData.IsOpenable()) { var player = (PlayerEntity)owner.OwnerEntity; player.playerMove.InterruptAutoRun(); var go = door.rawGameObject.Value; var playerPosition = player.RootGo().transform.position; var doorPosition = go.transform.position; var direction = (playerPosition - doorPosition); var dot = Vector3.Dot(direction, go.transform.forward); var rot = go.transform.localEulerAngles.y; rot = YawPitchUtility.Normalize(rot); float from = rot, to = 0; var state = door.doorData.State; var endState = state; if (dot > 0) { switch (state) { case (int)DoorState.Closed: to = from + OpenMaxAngle; endState = (int)DoorState.OpenMax; break; case (int)DoorState.OpenMin: to = from - OpenMinAngle; endState = (int)DoorState.Closed; break; case (int)DoorState.OpenMax: to = from - OpenMaxAngle; endState = (int)DoorState.Closed; break; } } else if (dot < 0) { switch (state) { case (int)DoorState.Closed: to = from + OpenMinAngle; endState = (int)DoorState.OpenMin; break; case (int)DoorState.OpenMin: to = from - OpenMinAngle; endState = (int)DoorState.Closed; break; case (int)DoorState.OpenMax: to = from - OpenMaxAngle; endState = (int)DoorState.Closed; break; } } if (endState != state) { player.stateInterface.State.OpenDoor(); if (SharedConfig.IsServer || SharedConfig.IsOffline) { door.doorData.State = (int)DoorState.Rotating; door.AddDoorRotate(from, from, to, endState); _logger.DebugFormat("Trigger Door From {0} {1} To {2} {3}", state, from, endState, to); switch ((DoorState)endState) { case DoorState.Closed: player.soundManager.Value.PlayOnce(XmlConfig.EPlayerSoundType.CloseDoor); break; case DoorState.OpenMax: case DoorState.OpenMin: player.soundManager.Value.PlayOnce(XmlConfig.EPlayerSoundType.OpenDoor); break; } } } } } }
private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera, Vector3 punchRotation, PlayerEntity player) { Vector3 lToCamera = calsOut.Offset; var clientTime = player.time.ClientTime; float lNewDistance = lToCamera.magnitude; bool collided = false; var startingRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation); var realArchorStart = calsOut.ArchorOffset; if (player.stateInterface.State.GetActionState() != ActionInConfig.Gliding && player.stateInterface.State.GetActionState() != ActionInConfig.Parachuting && player.gamePlay.GameState != Components.GameState.AirPlane) { TestArchorOffset(calsOut, player, ref realArchorStart); } var archorRotation = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0); var postOffsetFactor = ActualStartingPosition( calsOut.ArchorPosition + archorRotation * realArchorStart, archorRotation, calsOut.ArchorPostOffset + calsOut.PostOffset, _collisionLayers); var startingPosition = calsOut.FinalArchorPosition = calsOut.ArchorPosition + archorRotation * (realArchorStart + calsOut.ArchorPostOffset * postOffsetFactor + calsOut.PostOffset * postOffsetFactor); float actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers); var factor = 1f; if (actualDistance < lNewDistance) { collided = true; if (actualDistance < _collisionOffsetStartDistance) { factor = Mathf.Lerp(_collisionOffsetStartDistance, actualDistance, actualDistance / lNewDistance) / lNewDistance; startingPosition = calsOut.ArchorPosition + archorRotation * (realArchorStart + calsOut.ArchorPostOffset * factor * postOffsetFactor + calsOut.PostOffset * postOffsetFactor * factor); actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers); if (actualDistance >= lNewDistance) { collided = false; } } } var finalPostOffset = calsOut.Offset.normalized * actualDistance; if (collided && !player.appearanceInterface.Appearance.IsFirstPerson) { camera.LastCollisionOffset = finalPostOffset; camera.LastCollisionTime = clientTime; } else if (clientTime - camera.LastCollisionTime < camera.PostTransitionTime && !player.appearanceInterface.Appearance.IsFirstPerson) { finalPostOffset = PositionLerp(camera.LastCollisionOffset, finalPostOffset, (float)(clientTime - camera.LastCollisionTime) / camera.PostTransitionTime); } camera.PlayerFocusPosition = startingPosition; camera.Position = startingPosition + startingRotation * (finalPostOffset); camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation; camera.EulerAngle.x = YawPitchUtility.Normalize(camera.EulerAngle.x); camera.EulerAngle.y = YawPitchUtility.Normalize(camera.EulerAngle.y); camera.EulerAngle.z = YawPitchUtility.Normalize(camera.EulerAngle.z); camera.Fov = calsOut.Fov; camera.Far = calsOut.Far; camera.Near = calsOut.Near; #if UNITY_EDITOR var p1 = calsOut.ArchorPosition; var p2 = calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset; var p3 = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor); var p4 = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor + calsOut.PostOffset * postOffsetFactor * factor); var p5 = p4 + startingRotation * (calsOut.Offset.normalized * actualDistance); Debug.DrawLine(p1, p2, Color.red); Debug.DrawLine(p2, p3, Color.green); Debug.DrawLine(p3, p4, Color.blue); Debug.DrawLine(p4, p5, Color.yellow); #endif }
private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera, Vector3 punchRotation) { Vector3 lToCamera = calsOut.Offset; float lNewDistance = lToCamera.magnitude; bool collided = false; var archorRotation = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0); var postOffsetFactor = ActualStartingPosition( calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset, archorRotation, calsOut.ArchorPostOffset + calsOut.PostOffset, _collisionLayers); var startingPosition = calsOut.FinalArchorPosition = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * postOffsetFactor + calsOut.PostOffset * postOffsetFactor); var startingRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation); float actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers); var factor = 1f; if (actualDistance < lNewDistance) { if (actualDistance < _collisionOffsetStartDistance) { factor = actualDistance / lNewDistance; startingPosition = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor + calsOut.PostOffset * postOffsetFactor * factor); actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers); } } camera.PlayerFocusPosition = startingPosition; camera.Position = startingPosition + startingRotation * (calsOut.Offset.normalized * actualDistance); camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation; camera.EulerAngle.x = YawPitchUtility.Normalize(camera.EulerAngle.x); camera.EulerAngle.y = YawPitchUtility.Normalize(camera.EulerAngle.y); camera.EulerAngle.z = YawPitchUtility.Normalize(camera.EulerAngle.z); camera.Fov = calsOut.Fov; camera.Far = calsOut.Far; camera.Near = calsOut.Near; #if UNITY_EDITOR var p1 = calsOut.ArchorPosition; var p2 = calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset; var p3 = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor); var p4 = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor + calsOut.PostOffset * postOffsetFactor * factor); var p5 = p4 + startingRotation * (calsOut.Offset.normalized * actualDistance); Debug.DrawLine(p1, p2, Color.red); Debug.DrawLine(p2, p3, Color.green); Debug.DrawLine(p3, p4, Color.blue); Debug.DrawLine(p4, p5, Color.yellow); #endif }