From d089d9bfb2c3d82342dd397e9de55d035402094d Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 19 Oct 2024 14:58:16 -0700 Subject: [PATCH] Improve player movement and add collision --- Assets/Player.prefab | 28 +++++++++++++++++++++++++ Assets/Teo.cs | 11 +++++----- ProjectSettings/DynamicsManager.asset | 17 ++++++++------- ProjectSettings/Physics2DSettings.asset | 24 ++++++++++----------- 4 files changed, 54 insertions(+), 26 deletions(-) diff --git a/Assets/Player.prefab b/Assets/Player.prefab index 4c32a5c..5ecf60f 100644 --- a/Assets/Player.prefab +++ b/Assets/Player.prefab @@ -12,6 +12,7 @@ GameObject: - component: {fileID: 7692843314178062085} - component: {fileID: 6118034672792182209} - component: {fileID: 4194995354293255184} + - component: {fileID: -4152331571693237436} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -149,6 +150,33 @@ BoxCollider2D: m_AutoTiling: 0 m_Size: {x: 12.63, y: 12.63} m_EdgeRadius: 0 +--- !u!50 &-4152331571693237436 +Rigidbody2D: + serializedVersion: 5 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3739677681433878215} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 --- !u!1 &8669953498445216587 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Teo.cs b/Assets/Teo.cs index 01a6638..0cd5280 100644 --- a/Assets/Teo.cs +++ b/Assets/Teo.cs @@ -6,16 +6,15 @@ public class Teo : MonoBehaviour // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { - } // Update is called once per frame void Update() { - transform.Translate( - Input.GetAxis("Horizontal")*moveSpeed*Time.deltaTime, - Input.GetAxis("Vertical")*moveSpeed*Time.deltaTime, - 0 - ); + Rigidbody2D controller = GetComponent(); + controller.linearVelocity = new Vector2 ( + Input.GetAxis("Horizontal"), + Input.GetAxis("Vertical") + ).normalized * moveSpeed; } } diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index fc90ab9..6786f14 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,10 +3,11 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 13 - m_Gravity: {x: 0, y: -9.81, z: 0} + serializedVersion: 17 + m_Gravity: {x: 0, y: 0, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 + m_DefaultMaxDepenetrationVelocity: 10 m_SleepThreshold: 0.005 m_DefaultContactOffset: 0.01 m_DefaultSolverIterations: 6 @@ -16,21 +17,21 @@ PhysicsManager: m_EnableAdaptiveForce: 0 m_ClothInterCollisionDistance: 0.1 m_ClothInterCollisionStiffness: 0.2 - m_ContactsGeneration: 1 m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - m_AutoSimulation: 1 + m_SimulationMode: 0 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 + m_InvokeCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 m_BroadphaseType: 0 - m_WorldBounds: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 250, y: 250, z: 250} - m_WorldSubdivisions: 8 m_FrictionType: 0 m_EnableEnhancedDeterminism: 0 m_EnableUnifiedHeightmaps: 1 + m_ImprovedPatchFriction: 0 m_SolverType: 0 m_DefaultMaxAngularSpeed: 50 + m_ScratchBufferChunkCount: 4 + m_CurrentBackendId: 4072204805 + m_FastMotionThreshold: 3.4028235e+38 diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset index 6cfcdda..5667abc 100644 --- a/ProjectSettings/Physics2DSettings.asset +++ b/ProjectSettings/Physics2DSettings.asset @@ -3,12 +3,12 @@ --- !u!19 &1 Physics2DSettings: m_ObjectHideFlags: 0 - serializedVersion: 5 - m_Gravity: {x: 0, y: -9.81} + serializedVersion: 6 + m_Gravity: {x: 0, y: 0} m_DefaultMaterial: {fileID: 0} m_VelocityIterations: 8 m_PositionIterations: 3 - m_VelocityThreshold: 1 + m_BounceThreshold: 1 m_MaxLinearCorrection: 0.2 m_MaxAngularCorrection: 8 m_MaxTranslationSpeed: 100 @@ -19,6 +19,7 @@ Physics2DSettings: m_LinearSleepTolerance: 0.01 m_AngularSleepTolerance: 2 m_DefaultContactOffset: 0.01 + m_ContactThreshold: 0 m_JobOptions: serializedVersion: 2 useMultithreading: 0 @@ -39,18 +40,17 @@ Physics2DSettings: m_IslandSolverBodiesPerJob: 50 m_IslandSolverContactsPerJob: 50 m_SimulationMode: 0 + m_SimulationLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_MaxSubStepCount: 4 + m_MinSubStepFPS: 30 + m_UseSubStepping: 0 + m_UseSubStepContacts: 0 m_QueriesHitTriggers: 1 m_QueriesStartInColliders: 1 m_CallbacksOnDisable: 1 m_ReuseCollisionCallbacks: 1 m_AutoSyncTransforms: 0 - m_AlwaysShowColliders: 0 - m_ShowColliderSleep: 1 - m_ShowColliderContacts: 0 - m_ShowColliderAABB: 0 - m_ContactArrowScale: 0.2 - m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} - m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} - m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} - m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} + m_GizmoOptions: 10 m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff