player movement fix

This commit is contained in:
Oscar 2024-10-19 15:28:48 +03:00
parent a58e345bd6
commit de20b3ba8a
9 changed files with 45 additions and 58 deletions

View File

@ -211,4 +211,4 @@ AnimatorStateMachine:
m_EntryPosition: {x: 50, y: 120, z: 0} m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0} m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 6967950985112314046} m_DefaultState: {fileID: -2140190126868441861}

View File

@ -735,8 +735,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c15217f0dad9f164885e26dff8e9dab4, type: 3} m_Script: {fileID: 11500000, guid: c15217f0dad9f164885e26dff8e9dab4, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
walkSpeed: 150 walkSpeed: 100
runSpeed: 350 runSpeed: 200
jumpForce: 160 jumpForce: 160
groundCheckRadius: 0.14 groundCheckRadius: 0.14
groundCheck: {fileID: 4628745799520432865} groundCheck: {fileID: 4628745799520432865}

View File

@ -494,7 +494,7 @@ Transform:
m_GameObject: {fileID: 183742006} m_GameObject: {fileID: 183742006}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.531, z: 2.306} m_LocalPosition: {x: 0, y: 2.201, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -3224,7 +3224,7 @@ MonoBehaviour:
authenticator: {fileID: 0} authenticator: {fileID: 0}
playerPrefab: {fileID: 1245232378091721159, guid: 19b8b462ea29c124ca06ccb21b9751f9, type: 3} playerPrefab: {fileID: 1245232378091721159, guid: 19b8b462ea29c124ca06ccb21b9751f9, type: 3}
autoCreatePlayer: 1 autoCreatePlayer: 1
playerSpawnMethod: 0 playerSpawnMethod: 1
spawnPrefabs: [] spawnPrefabs: []
exceptionsDisconnect: 1 exceptionsDisconnect: 1
snapshotSettings: snapshotSettings:

View File

@ -9,7 +9,7 @@ public class JoinCollider : MonoBehaviour
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
door.SetActive(true); door.SetActive(true);
networkManager.networkAddress = "localhost"; // networkManager.networkAddress = "localhost";
networkManager.StartClient(); networkManager.StartClient();
} }
} }

View File

@ -30,6 +30,7 @@ namespace Player.States
_player.animator.SetBool(AnimJump, false); _player.animator.SetBool(AnimJump, false);
} }
private Vector3 _velocity;
public override void Update() public override void Update()
{ {
if (_player.isGrounded && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f) && Input.GetKey(KeyCode.LeftShift)) if (_player.isGrounded && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f) && Input.GetKey(KeyCode.LeftShift))
@ -40,9 +41,13 @@ namespace Player.States
{ {
_player.StateMachine.SetCurrentState(PlayerState.Walk); _player.StateMachine.SetCurrentState(PlayerState.Walk);
} }
_velocity = _player.moveDirection * (_player.runSpeed * .5f) * Time.fixedDeltaTime;
}
Vector3 velocity = _player.moveDirection * (_player.runSpeed * .5f * Time.deltaTime); public override void FixedUpdate()
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z); {
_player.playerRigidbody.velocity = new Vector3(_velocity.x, _player.playerRigidbody.velocity.y, _velocity.z) ;
} }
public override void Exit() public override void Exit()

View File

@ -18,18 +18,22 @@ namespace Player.States
_player.animator.SetBool(AnimRun, true); _player.animator.SetBool(AnimRun, true);
} }
private Vector3 _velocity;
public override void Update() public override void Update()
{ {
Vector3 velocity = _player.moveDirection * (_player.runSpeed * Time.deltaTime); _velocity = _player.moveDirection * _player.runSpeed * Time.fixedDeltaTime;
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z);
if (Input.GetKeyUp(KeyCode.LeftShift) || (Input.GetAxis("Horizontal") == 0f && Input.GetAxis("Vertical") == 0f)) if (Input.GetKeyUp(KeyCode.LeftShift) || (Input.GetAxis("Horizontal") == 0f && Input.GetAxis("Vertical") == 0f))
{ {
_player.StateMachine.SetCurrentState(PlayerState.Walk); _player.StateMachine.SetCurrentState(PlayerState.Walk);
} }
} }
public override void FixedUpdate()
{
_player.playerRigidbody.velocity = new Vector3(_velocity.x, _player.playerRigidbody.velocity.y, _velocity.z) ;
}
public override void Exit() public override void Exit()
{ {
_player.animator.SetBool(AnimRun, false); _player.animator.SetBool(AnimRun, false);

View File

@ -18,18 +18,23 @@ namespace Player.States
_player.animator.SetBool(AnimWalk, true); _player.animator.SetBool(AnimWalk, true);
} }
private Vector3 _velocity;
public override void Update() public override void Update()
{ {
Vector3 velocity = _player.moveDirection * (_player.walkSpeed * Time.deltaTime); _velocity = _player.moveDirection * _player.walkSpeed * Time.fixedDeltaTime;
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z);
if (Input.GetKey(KeyCode.LeftShift) && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f)) if (Input.GetKey(KeyCode.LeftShift) && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f))
{ {
_player.StateMachine.SetCurrentState(PlayerState.Run); _player.StateMachine.SetCurrentState(PlayerState.Run);
} }
} }
public override void FixedUpdate()
{
_player.playerRigidbody.velocity = new Vector3(_velocity.x, _player.playerRigidbody.velocity.y, _velocity.z);
}
public override void Exit() public override void Exit()
{ {
_player.animator.SetBool(AnimWalk, false); _player.animator.SetBool(AnimWalk, false);

View File

@ -19,7 +19,7 @@ MonoBehaviour:
m_RendererDataList: m_RendererDataList:
- {fileID: 11400000, guid: f288ae1f4751b564a96ac7587541f7a2, type: 2} - {fileID: 11400000, guid: f288ae1f4751b564a96ac7587541f7a2, type: 2}
- {fileID: 11400000, guid: 3ce065fd0b794984db4fd7a73c364ded, type: 2} - {fileID: 11400000, guid: 3ce065fd0b794984db4fd7a73c364ded, type: 2}
- {fileID: 11400000, guid: a04c28107d77d5e42b7155783b8475b6, type: 2} - {fileID: 0}
m_DefaultRendererIndex: 0 m_DefaultRendererIndex: 0
m_RequireDepthTexture: 0 m_RequireDepthTexture: 0
m_RequireOpaqueTexture: 1 m_RequireOpaqueTexture: 1
@ -86,13 +86,13 @@ MonoBehaviour:
bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3}
m_PrefilteringModeMainLightShadows: 3 m_PrefilteringModeMainLightShadows: 3
m_PrefilteringModeAdditionalLight: 4 m_PrefilteringModeAdditionalLight: 4
m_PrefilteringModeAdditionalLightShadows: 0 m_PrefilteringModeAdditionalLightShadows: 2
m_PrefilterXRKeywords: 1 m_PrefilterXRKeywords: 1
m_PrefilteringModeForwardPlus: 1 m_PrefilteringModeForwardPlus: 1
m_PrefilteringModeDeferredRendering: 0 m_PrefilteringModeDeferredRendering: 0
m_PrefilteringModeScreenSpaceOcclusion: 1 m_PrefilteringModeScreenSpaceOcclusion: 1
m_PrefilterDebugKeywords: 1 m_PrefilterDebugKeywords: 1
m_PrefilterWriteRenderingLayers: 0 m_PrefilterWriteRenderingLayers: 1
m_PrefilterHDROutput: 1 m_PrefilterHDROutput: 1
m_PrefilterSSAODepthNormals: 0 m_PrefilterSSAODepthNormals: 0
m_PrefilterSSAOSourceDepthLow: 1 m_PrefilterSSAOSourceDepthLow: 1
@ -106,9 +106,9 @@ MonoBehaviour:
m_PrefilterDBufferMRT1: 1 m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1 m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 0 m_PrefilterDBufferMRT3: 0
m_PrefilterSoftShadowsQualityLow: 0 m_PrefilterSoftShadowsQualityLow: 1
m_PrefilterSoftShadowsQualityMedium: 0 m_PrefilterSoftShadowsQualityMedium: 1
m_PrefilterSoftShadowsQualityHigh: 0 m_PrefilterSoftShadowsQualityHigh: 1
m_PrefilterSoftShadows: 0 m_PrefilterSoftShadows: 0
m_PrefilterScreenCoord: 1 m_PrefilterScreenCoord: 1
m_PrefilterNativeRenderPass: 1 m_PrefilterNativeRenderPass: 1