пінгвін ходіт

This commit is contained in:
MrTorex committed 2026-01-31 00:02:35 +03:00
1 parent 158850aa45
commit 0090d6d774
10 files changed
+545 -13

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d1cbbd4cb454d23a8d6c16c6ef12c7b
timeCreated: 1769791134
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6158f3abaa124e198d646274f7cea710
timeCreated: 1769791162
@@ -0,0 +1,90 @@
using UnityEngine;
using Code.Input;
namespace Code.Gameplay.Player
{
public class PlayerMovement : MonoBehaviour
{
[Header("References")]
[SerializeField] private Rigidbody2D _rb;
[SerializeField] private Transform _groundCheck;
[SerializeField] private LayerMask _groundLayer;
[Header("Movement")]
[SerializeField] private float _moveSpeed = 5f;
[SerializeField] private float _sprintSpeedMultiplier = 1.8f;
[SerializeField] private float _jumpForce = 12f;
[Header("Ground Check")]
[SerializeField] private float _groundCheckRadius = 0.2f;
private IInputService _input;
private bool _isGrounded;
private bool _jumpRequested;
public bool IsGrounded => _isGrounded;
public void Construct(IInputService input)
{
_input = input;
}
private void Update()
{
HandleInput();
CheckGround();
}
private void FixedUpdate()
{
Move();
HandleJump();
}
private void HandleInput()
{
transform.rotation = _input.MoveInput switch
{
> 0 => Quaternion.identity,
< 0 => Quaternion.Euler(0, -180, 0),
_ => transform.rotation
};
if (_input.JumpPressed && !_jumpRequested)
{
_jumpRequested = true;
}
}
private void CheckGround()
{
_isGrounded = Physics2D.OverlapCircle(_groundCheck.position, _groundCheckRadius, _groundLayer);
}
private void Move()
{
float moveInput = _input.MoveInput;
float speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed;
float targetVelocityX = moveInput * speed;
// Плавное изменение скорости (опционально, можно и напрямую)
_rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y);
}
private void HandleJump()
{
if (_jumpRequested && _isGrounded)
{
_rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce);
_jumpRequested = false;
}
}
// Для отладки
private void OnDrawGizmosSelected()
{
if (_groundCheck != null)
Gizmos.DrawWireSphere(_groundCheck.position, _groundCheckRadius);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0c9ba2abef40495ca9fdfbe42f74330d
timeCreated: 1769791173
+3
View File
@@ -12,6 +12,9 @@ namespace Code.Input
Vector2 MainMenuParalax { get; } Vector2 MainMenuParalax { get; }
float MoveInput { get; } float MoveInput { get; }
bool JumpPressed { get; }
bool SprintHeld { get; }
bool AttackPressed { get; }
void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action); void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
+6
View File
@@ -11,6 +11,9 @@ namespace Code.Input
public Vector2 MainMenuParalax { get; private set; } public Vector2 MainMenuParalax { get; private set; }
public float MoveInput { get; private set; } public float MoveInput { get; private set; }
public bool JumpPressed { get; private set; }
public bool SprintHeld { get; private set; }
public bool AttackPressed { get; private set; }
public InputService(InputActionAsset inputActionAsset) public InputService(InputActionAsset inputActionAsset)
{ {
@@ -28,6 +31,9 @@ namespace Code.Input
{ {
var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay]; var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay];
BindAxis(map, "Move", v => MoveInput = v); BindAxis(map, "Move", v => MoveInput = v);
BindButton(map, "Jump", v => JumpPressed = v);
BindButton(map, "Sprint", v => SprintHeld = v);
BindButton(map, "Attack", v => AttackPressed = v);
} }
private void SetupMainMenuInputCallbacks() private void SetupMainMenuInputCallbacks()
+3 -5
View File
@@ -1,4 +1,5 @@
using Code.DI; using Code.DI;
using Code.Gameplay.Player;
using Code.Input; using Code.Input;
using UnityEngine; using UnityEngine;
@@ -12,11 +13,8 @@ namespace Code.UI
{ {
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>(); _inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
_inputService.EnableMap(ActionMapping.Gameplay); _inputService.EnableMap(ActionMapping.Gameplay);
}
FindFirstObjectByType<PlayerMovement>().Construct(_inputService);
public void Update()
{
Debug.Log(_inputService.MoveInput);
} }
} }
} }
+351
View File
@@ -1174,6 +1174,144 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1211830912} m_GameObject: {fileID: 1211830912}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1464259587
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1464259589}
- component: {fileID: 1464259588}
- component: {fileID: 1464259590}
m_Layer: 3
m_Name: ground
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &1464259588
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1464259587}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!4 &1464259589
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1464259587}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 10, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &1464259590
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1464259587}
m_Enabled: 1
serializedVersion: 3
m_Density: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ForceSendLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ForceReceiveLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ContactCaptureLayers:
serializedVersion: 2
m_Bits: 4294967295
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 1
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!1 &1596676852 --- !u!1 &1596676852
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1221,6 +1359,217 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1596676852} m_GameObject: {fileID: 1596676852}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1616841230
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1616841232}
- component: {fileID: 1616841231}
- component: {fileID: 1616841235}
- component: {fileID: 1616841233}
- component: {fileID: 1616841234}
- component: {fileID: 1616841236}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &1616841231
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: 21300000, guid: 901639f1dddd7b04aa3c943786d274d5, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!4 &1616841232
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 4, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &1616841233
Rigidbody2D:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 100
m_LinearDamping: 0
m_AngularDamping: 0.05
m_GravityScale: 5
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_Interpolate: 0
m_SleepingMode: 0
m_CollisionDetection: 1
m_Constraints: 4
--- !u!114 &1616841234
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0c9ba2abef40495ca9fdfbe42f74330d, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Code.Gameplay.Player.PlayerMovement
_rb: {fileID: 1616841233}
_groundCheck: {fileID: 1464259589}
_groundLayer:
serializedVersion: 2
m_Bits: 8
_moveSpeed: 5
_sprintSpeedMultiplier: 1.8
_jumpForce: 12
_groundCheckRadius: 0.2
--- !u!61 &1616841235
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
m_Enabled: 1
serializedVersion: 3
m_Density: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ForceSendLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ForceReceiveLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ContactCaptureLayers:
serializedVersion: 2
m_Bits: 4294967295
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 0
m_Offset: {x: -0.045, y: -1}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 5.12, y: 5.12}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
m_Size: {x: 1.85, y: 2.7}
m_EdgeRadius: 0
--- !u!95 &1616841236
Animator:
serializedVersion: 7
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1616841230}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: ba9e8b2f4d5d07f4e84e9f05710f122c, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_AnimatePhysics: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!1 &1677702646 --- !u!1 &1677702646
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1426,3 +1775,5 @@ SceneRoots:
- {fileID: 619394802} - {fileID: 619394802}
- {fileID: 1163535557} - {fileID: 1163535557}
- {fileID: 553971734} - {fileID: 553971734}
- {fileID: 1464259589}
- {fileID: 1616841232}
@@ -35,7 +35,7 @@
"id": "0d58d58e-82df-47fc-8847-b7d4ed12b3c1", "id": "0d58d58e-82df-47fc-8847-b7d4ed12b3c1",
"actions": [ "actions": [
{ {
"name": "New action", "name": "Jump",
"type": "Button", "type": "Button",
"id": "2be1437b-be70-49bc-968a-4211a82398ad", "id": "2be1437b-be70-49bc-968a-4211a82398ad",
"expectedControlType": "", "expectedControlType": "",
@@ -51,17 +51,35 @@
"processors": "", "processors": "",
"interactions": "", "interactions": "",
"initialStateCheck": true "initialStateCheck": true
},
{
"name": "Attack",
"type": "Button",
"id": "9cf15cdb-4f45-4453-9d26-cd8a660855c6",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Sprint",
"type": "Button",
"id": "9b34ee00-3c84-4dc2-8d87-c617ee745260",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
} }
], ],
"bindings": [ "bindings": [
{ {
"name": "", "name": "",
"id": "eeb7e7e7-fdf7-4f44-9cec-45cfe0fbc414", "id": "eeb7e7e7-fdf7-4f44-9cec-45cfe0fbc414",
"path": "", "path": "<Keyboard>/space",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": ";Keyboard&Mouse",
"action": "New action", "action": "Jump",
"isComposite": false, "isComposite": false,
"isPartOfComposite": false "isPartOfComposite": false
}, },
@@ -82,7 +100,18 @@
"path": "<Keyboard>/a", "path": "<Keyboard>/a",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": ";Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "negative",
"id": "6fefa1fa-2250-4435-ad8d-e32a6bc63a1d",
"path": "<Keyboard>/leftArrow",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Move", "action": "Move",
"isComposite": false, "isComposite": false,
"isPartOfComposite": true "isPartOfComposite": true
@@ -93,10 +122,54 @@
"path": "<Keyboard>/d", "path": "<Keyboard>/d",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": ";Keyboard&Mouse",
"action": "Move", "action": "Move",
"isComposite": false, "isComposite": false,
"isPartOfComposite": true "isPartOfComposite": true
},
{
"name": "positive",
"id": "877a48a0-8255-444d-9e4a-934937238c2f",
"path": "<Keyboard>/rightArrow",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "75a6406d-8d53-4e3f-88c4-53e8eb898f5c",
"path": "<Keyboard>/f",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Attack",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "58b873f6-fb11-4214-8819-97d4f68f9d8b",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Attack",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "5edbe4a6-65bd-4daf-ab2b-c2ed63691367",
"path": "<Keyboard>/shift",
"interactions": "",
"processors": "",
"groups": "",
"action": "Sprint",
"isComposite": false,
"isPartOfComposite": false
} }
] ]
}, },
+4 -2
View File
@@ -2,13 +2,13 @@
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 2 serializedVersion: 3
tags: [] tags: []
layers: layers:
- Default - Default
- TransparentFX - TransparentFX
- Ignore Raycast - Ignore Raycast
- - Provides Contact
- Water - Water
- UI - UI
- -
@@ -41,3 +41,5 @@ TagManager:
- name: Default - name: Default
uniqueID: 0 uniqueID: 0
locked: 0 locked: 0
m_RenderingLayers:
- Default