diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 1a09cb7..46ddcf1 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -47,6 +47,7 @@ + @@ -76,6 +77,7 @@ + @@ -91,6 +93,7 @@ + diff --git a/Assets/Material/ball.physicMaterial b/Assets/Material/ball.physicMaterial index 5bbef25..4c8f72d 100644 --- a/Assets/Material/ball.physicMaterial +++ b/Assets/Material/ball.physicMaterial @@ -10,6 +10,6 @@ PhysicsMaterial: serializedVersion: 2 m_DynamicFriction: 0.6 m_StaticFriction: 0.6 - m_Bounciness: 0 + m_Bounciness: 0.5 m_FrictionCombine: 0 m_BounceCombine: 0 diff --git a/Assets/Prefab/Sphere.prefab b/Assets/Prefab/Sphere.prefab index 9f02576..c0ca996 100644 --- a/Assets/Prefab/Sphere.prefab +++ b/Assets/Prefab/Sphere.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 7093238386133182062} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 933.9104, y: -0, z: 1958.721} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 680e16e..68809d1 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -270,7 +270,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4058037651045720570, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} propertyPath: m_LocalPosition.x - value: -1.88 + value: -1.936 objectReference: {fileID: 0} - target: {fileID: 4058037651045720570, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} propertyPath: m_LocalPosition.y @@ -278,7 +278,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4058037651045720570, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} propertyPath: m_LocalPosition.z - value: -0.023 + value: -0.018 objectReference: {fileID: 0} - target: {fileID: 4058037651045720570, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} propertyPath: m_LocalRotation.w @@ -315,6 +315,24 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} insertIndex: -1 addedObject: {fileID: 1075063774} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063778} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063777} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063783} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063782} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063781} + - targetCorrespondingSourceObject: {fileID: 3682496519326268224, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1075063784} m_SourcePrefab: {fileID: 100100000, guid: 216411d97f5a68f4a87e27e0d0ade2d7, type: 3} --- !u!1 &141601765 GameObject: @@ -685,6 +703,59 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 599855876} m_CullTransparentMesh: 1 +--- !u!1 &745371152 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 745371154} + - component: {fileID: 745371153} + m_Layer: 0 + m_Name: ScoreZone + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &745371153 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 745371152} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 2.8223405, y: 0.11762619, z: 3.7329292} + m_Center: {x: -0.18779182, y: 0.4411869, z: 0.09677839} +--- !u!4 &745371154 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 745371152} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -1.03147, y: 11.41, z: -0.3} + 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!1 &832575517 GameObject: m_ObjectHideFlags: 0 @@ -734,6 +805,11 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &914997203 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4708965725589232951, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + m_PrefabInstance: {fileID: 1616289390} + m_PrefabAsset: {fileID: 0} --- !u!4 &942389252 stripped Transform: m_CorrespondingSourceObject: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} @@ -757,7 +833,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &968778833 MonoBehaviour: m_ObjectHideFlags: 0 @@ -841,13 +917,13 @@ MonoBehaviour: PreviewVisible: 1 RuntimeOcclusion: 0 RuntimeCollider: 0 - mTrackableName: z7784214748644_b3ccece5f73d2a2e0581f0a58b2b8aa7 + mTrackableName: snake mInitializedInEditor: 1 - mDataSetPath: Vuforia/DatabaseName.xml - mAspectRatio: 2.2210424 + mDataSetPath: Vuforia/NGTUAN.xml + mAspectRatio: 1.4521515 mImageTargetType: 0 mWidth: 5 - mHeight: 11.105212 + mHeight: 7.2607574 mRuntimeTexture: {fileID: 0} mMotionHint: 1 mTrackingOptimization: 0 @@ -883,8 +959,8 @@ MonoBehaviour: m_EditorClassIdentifier: Vuforia.Unity.Engine.dll::Vuforia.ImageTargetPreview mObserverBehaviour: {fileID: 968778834} mHiddenRoot: {fileID: 0} - mTargetName: z7784214748644_b3ccece5f73d2a2e0581f0a58b2b8aa7 - mDatasetName: Vuforia/DatabaseName.xml + mTargetName: snake + mDatasetName: Vuforia/NGTUAN.xml mCastedBehaviour: {fileID: 968778834} mMeshFilter: {fileID: 0} mMeshRenderer: {fileID: 0} @@ -911,6 +987,138 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Assembly-CSharp::ScoreManager scoreText: {fileID: 38800816} +--- !u!65 &1075063777 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.77672637, y: 0.8418276, z: 0.13022546} + m_Center: {x: -0.050724592, y: 0.0023020746, z: 0.37827945} +--- !u!54 &1075063778 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + serializedVersion: 5 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_CenterOfMass: {x: 0, y: 0, z: 0} + m_InertiaTensor: {x: 1, y: 1, z: 1} + m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ImplicitCom: 1 + m_ImplicitTensor: 1 + m_UseGravity: 0 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 126 + m_CollisionDetection: 0 +--- !u!65 &1075063781 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.060377598, y: 0.8473031, z: 0.596032} + m_Center: {x: 0.37287885, y: 0.005039835, z: 0.01628306} +--- !u!65 &1075063782 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.63381463, y: 0.8473031, z: 0.08439002} + m_Center: {x: 0.015751136, y: 0.005039835, z: -0.3373408} +--- !u!65 &1075063783 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.11698814, y: 0.8473031, z: 0.6487788} + m_Center: {x: -0.3805935, y: 0.005039835, z: 0.023673272} +--- !u!65 &1075063784 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1075063772} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.71972764, y: 0.09103336, z: 0.6759124} + m_Center: {x: -0.0054461, y: -0.373096, z: 0.010183764} --- !u!1 &1172560393 GameObject: m_ObjectHideFlags: 0 @@ -1305,21 +1513,33 @@ PrefabInstance: propertyPath: m_Name value: Ring objectReference: {fileID: 0} + - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + propertyPath: m_LocalScale.x + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + propertyPath: m_LocalScale.y + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + propertyPath: m_LocalScale.z + value: 5 + objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalPosition.x - value: -0.3635254 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalPosition.y - value: -0.0004516709 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalPosition.z - value: 0.17551857 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalRotation.w - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalRotation.x @@ -1327,7 +1547,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalRotation.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalRotation.z @@ -1339,7 +1559,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalEulerAnglesHint.y - value: 180 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} propertyPath: m_LocalEulerAnglesHint.z @@ -1351,7 +1571,13 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} insertIndex: -1 addedObject: {fileID: 1075063773} - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 4708965725589232951, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + insertIndex: -1 + addedObject: {fileID: 2027009480} + - targetCorrespondingSourceObject: {fileID: 4708965725589232951, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} + insertIndex: -1 + addedObject: {fileID: 2027009479} m_SourcePrefab: {fileID: 100100000, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} --- !u!1 &1660361740 GameObject: @@ -1431,13 +1657,13 @@ MonoBehaviour: PreviewVisible: 1 RuntimeOcclusion: 0 RuntimeCollider: 0 - mTrackableName: z7784214748644_b3ccece5f73d2a2e0581f0a58b2b8aa7 + mTrackableName: cherry mInitializedInEditor: 1 - mDataSetPath: Vuforia/DatabaseName.xml - mAspectRatio: 2.2210424 + mDataSetPath: Vuforia/NGTUAN.xml + mAspectRatio: 1.4603536 mImageTargetType: 0 mWidth: 5 - mHeight: 11.105212 + mHeight: 7.3017683 mRuntimeTexture: {fileID: 0} mMotionHint: 1 mTrackingOptimization: 0 @@ -1473,8 +1699,8 @@ MonoBehaviour: m_EditorClassIdentifier: Vuforia.Unity.Engine.dll::Vuforia.ImageTargetPreview mObserverBehaviour: {fileID: 1660361742} mHiddenRoot: {fileID: 0} - mTargetName: z7784214748644_b3ccece5f73d2a2e0581f0a58b2b8aa7 - mDatasetName: Vuforia/DatabaseName.xml + mTargetName: cherry + mDatasetName: Vuforia/NGTUAN.xml mCastedBehaviour: {fileID: 1660361742} mMeshFilter: {fileID: 0} mMeshRenderer: {fileID: 0} @@ -1497,6 +1723,7 @@ MonoBehaviour: m_EditorClassIdentifier: Assembly-CSharp::PlayerController joystick: {fileID: 1239197812} moveSpeed: 2 + animator: {fileID: 0} --- !u!114 &1755326608 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1523,7 +1750,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalPosition.x - value: 0.11936338 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalPosition.y @@ -1531,7 +1758,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalPosition.z - value: -0.14514594 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalRotation.w @@ -1539,15 +1766,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalRotation.x - value: -0 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalRotation.y - value: -0 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalRotation.z - value: -0 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3426146483806157536, guid: 810eccd8d23152e4e873f7c1a46a53bc, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -1588,6 +1815,54 @@ Transform: m_CorrespondingSourceObject: {fileID: 5337411849267447693, guid: f1ed58764d968b047b58d640e9cf1417, type: 3} m_PrefabInstance: {fileID: 1616289390} m_PrefabAsset: {fileID: 0} +--- !u!65 &2027009479 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 914997203} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1.5552647, y: 3.8137977, z: 1.8599999} + m_Center: {x: -0.6316332, y: 1.9073505, z: -0.00000019073487} +--- !u!54 &2027009480 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 914997203} + serializedVersion: 5 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_CenterOfMass: {x: 0, y: 0, z: 0} + m_InertiaTensor: {x: 1, y: 1, z: 1} + m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ImplicitCom: 1 + m_ImplicitTensor: 1 + m_UseGravity: 0 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 126 + m_CollisionDetection: 0 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -1599,3 +1874,4 @@ SceneRoots: - {fileID: 1660361743} - {fileID: 1429989164} - {fileID: 141601768} + - {fileID: 745371154} diff --git a/Assets/Script/ARFirstPersonController.cs b/Assets/Script/ARFirstPersonController.cs new file mode 100644 index 0000000..ae18561 --- /dev/null +++ b/Assets/Script/ARFirstPersonController.cs @@ -0,0 +1,23 @@ +using UnityEngine; + +public class ARFirstPersonController : MonoBehaviour +{ + public Transform player; // Kéo nhân vật vào đây + public Transform imageTarget; // Kéo ImageTarget vào đây + public Vector3 viewOffset = new Vector3(0, -1.6f, 0.5f); // Điều chỉnh để mắt nhân vật khớp với camera + + void LateUpdate() + { + if (player == null || imageTarget == null) return; + + // Ép vị trí của toàn bộ ImageTarget di chuyển sao cho Player luôn nằm ở vị trí Camera + // Điều này tạo ra góc nhìn thứ nhất trong AR + Vector3 targetPosition = Camera.main.transform.position + Camera.main.transform.TransformDirection(viewOffset); + + // Di chuyển ImageTarget để bù trừ vị trí + imageTarget.position = targetPosition; + + // Xoay ImageTarget để hướng nhìn của nhân vật khớp với hướng điện thoại + imageTarget.rotation = Quaternion.LookRotation(Camera.main.transform.forward); + } +} diff --git a/Assets/Script/ARFirstPersonController.cs.meta b/Assets/Script/ARFirstPersonController.cs.meta new file mode 100644 index 0000000..596d7e8 --- /dev/null +++ b/Assets/Script/ARFirstPersonController.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 9969d44b616718648be576e1df5cae97 \ No newline at end of file diff --git a/Assets/Script/BallShooter.cs b/Assets/Script/BallShooter.cs index e7d6d79..ddb6903 100644 --- a/Assets/Script/BallShooter.cs +++ b/Assets/Script/BallShooter.cs @@ -7,16 +7,29 @@ public class BallShooter : MonoBehaviour public float shootForce = 500f; public float upwardForce = 200f; // Lực ném vòng cung lên trên - // Gọi hàm này khi bấm nút Ném trên UI public void ShootBall() { - GameObject newBall = Instantiate(ballPrefab, shootPoint.position, shootPoint.rotation); + // 1. Lấy vị trí ném: Từ Camera lùi xuống dưới một chút (giống tay người cầm bóng) + Vector3 spawnPosition = Camera.main.transform.position + + Camera.main.transform.forward * 0.5f + - Camera.main.transform.up * 0.2f; + + // 2. Tạo quả bóng + GameObject newBall = Instantiate(ballPrefab, spawnPosition, Camera.main.transform.rotation); + + // 3. Đảm bảo bóng không bị dính vào Image Target + newBall.transform.SetParent(null); + Rigidbody rb = newBall.GetComponent(); + if (rb != null) + { + // 4. Lấy hướng nhìn của điện thoại + Vector3 shootDirection = Camera.main.transform.forward; + + // 5. Thêm lực ném (Mạnh hơn một chút để bay tới rổ trên bàn) + rb.AddForce(shootDirection * shootForce + Vector3.up * upwardForce); + } - // Thêm lực để quả bóng bay về phía trước và hơi hếch lên trên - rb.AddForce(shootPoint.forward * shootForce + Vector3.up * upwardForce); - - // Hủy quả bóng sau 5 giây để tránh lag game Destroy(newBall, 5f); } } \ No newline at end of file diff --git a/Assets/Script/BouncyBall.cs b/Assets/Script/BouncyBall.cs new file mode 100644 index 0000000..cacdd9e --- /dev/null +++ b/Assets/Script/BouncyBall.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +public class BouncyBall : MonoBehaviour +{ + void Start() + { + // Tự động gán Tag để chắc chắn ScoreManager nhận ra quả bóng + gameObject.tag = "Ball"; + + Rigidbody rb = GetComponent(); + if (rb != null) + { + // Đảm bảo quả bóng có trọng lượng và không quá nặng + rb.mass = 0.6f; // Khối lượng chuẩn quả bóng rổ (kg) + rb.collisionDetectionMode = CollisionDetectionMode.Continuous; + } + + Collider col = GetComponent(); + if (col != null) + { + // Tạo Physic Material bằng code nếu chưa có + PhysicsMaterial bouncyMat = new PhysicsMaterial("BasketballMaterial"); + bouncyMat.bounciness = 0.8f; // Độ nảy (0 đến 1) + bouncyMat.bounceCombine = PhysicsMaterialCombine.Maximum; + bouncyMat.frictionCombine = PhysicsMaterialCombine.Minimum; + bouncyMat.staticFriction = 0.4f; + bouncyMat.dynamicFriction = 0.4f; + + col.material = bouncyMat; + } + } +} diff --git a/Assets/Script/BouncyBall.cs.meta b/Assets/Script/BouncyBall.cs.meta new file mode 100644 index 0000000..dc986c4 --- /dev/null +++ b/Assets/Script/BouncyBall.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 15dabd6ae947f12439f46655ed59fd7c \ No newline at end of file diff --git a/Assets/Script/CameraFollow.cs b/Assets/Script/CameraFollow.cs new file mode 100644 index 0000000..c9a4a2b --- /dev/null +++ b/Assets/Script/CameraFollow.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +public class CameraFollow : MonoBehaviour +{ + public Transform target; // Nhân vật (Player) + public Vector3 headOffset = new Vector3(0, 1.6f, 0.2f); // Vị trí mắt so với chân nhân vật + + void LateUpdate() + { + if (target == null) return; + + // Đặt camera ngay tại vị trí "mắt" của nhân vật + transform.position = target.position + target.TransformDirection(headOffset); + + // Camera luôn nhìn theo hướng xoay của nhân vật + transform.rotation = target.rotation; + } +} diff --git a/Assets/Script/CameraFollow.cs.meta b/Assets/Script/CameraFollow.cs.meta new file mode 100644 index 0000000..268bc2a --- /dev/null +++ b/Assets/Script/CameraFollow.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3918e143eb5bc084a9998b8660c75684 \ No newline at end of file diff --git a/Assets/Script/PlayerController.cs b/Assets/Script/PlayerController.cs index 2892534..b7366e5 100644 --- a/Assets/Script/PlayerController.cs +++ b/Assets/Script/PlayerController.cs @@ -4,6 +4,7 @@ public class PlayerController : MonoBehaviour { public Joystick joystick; // Kéo Fixed Joystick ở Canvas vào đây public float moveSpeed = 2f; + public Animator animator; // Kéo Animator của nhân vật vào đây void Update() { @@ -19,12 +20,22 @@ public class PlayerController : MonoBehaviour // Di chuyển object theo trục X và Z Vector3 direction = new Vector3(horizontal, 0, vertical).normalized; + float currentSpeed = direction.magnitude * moveSpeed; + transform.Translate(direction * moveSpeed * Time.deltaTime, Space.World); - // (Tùy chọn) Xoay object theo hướng di chuyển + // Xoay object mượt mà theo hướng di chuyển if (direction != Vector3.zero) { - transform.forward = direction; + Quaternion targetRotation = Quaternion.LookRotation(direction); + transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 15f * Time.deltaTime); + } + + // Cập nhật Animator + if (animator != null) + { + // Giả sử Animator có parameter "Speed" kiểu Float + animator.SetFloat("Speed", currentSpeed); } } } \ No newline at end of file diff --git a/Assets/Script/ScoreManager.cs b/Assets/Script/ScoreManager.cs index 718607f..216b4f8 100644 --- a/Assets/Script/ScoreManager.cs +++ b/Assets/Script/ScoreManager.cs @@ -6,20 +6,55 @@ public class ScoreManager : MonoBehaviour public TextMeshProUGUI scoreText; // Kéo UI Text điểm số vào đây private int currentScore = 0; + void Start() + { + currentScore = 0; + UpdateScoreUI(); + + // CHẨN ĐOÁN LỖI: + Collider col = GetComponent(); + if (col == null) + Debug.LogError("LỖI NẶNG: Object này (" + gameObject.name + ") CHƯA CÓ COLLIDER. Hãy add Box Collider ngay!"); + else if (!col.isTrigger) + Debug.LogWarning("CẢNH BÁO: Collider của rổ chưa tích 'Is Trigger'. Hãy tích vào!"); + + Debug.Log("Script ScoreManager đang hoạt động trên: " + gameObject.name + ""); + } + + // Bắt va chạm kiểu Trigger (Xuyên qua) private void OnTriggerEnter(Collider other) { - // Kiểm tra xem vật lọt qua rổ có phải là bóng không - if (other.CompareTag("Ball")) + GhiDiem(other.gameObject, "TRIGGER"); + } + + // Bắt va chạm kiểu Vật lý (Đập vào nhau) - Dự phòng nếu bạn chưa tích Is Trigger + private void OnCollisionEnter(Collision collision) + { + GhiDiem(collision.gameObject, "PHYSICS"); + } + + void GhiDiem(GameObject obj, string type) + { + Debug.Log("PHÁT HIỆN VA CHẠM [" + type + "] với: " + obj.name + " | Tag: " + obj.tag); + + if (obj.CompareTag("Ball") || obj.name.Contains("Sphere") || obj.name.Contains("ball")) { - currentScore += 2; // Cộng 2 điểm + currentScore += 2; UpdateScoreUI(); - - // (Tùy chọn) Thêm hiệu ứng âm thanh hoặc Particle vào đây + Debug.Log("===> GHI ĐIỂM THÀNH CÔNG! Điểm hiện tại: " + currentScore + ""); + Destroy(obj, 0.2f); } } void UpdateScoreUI() { - scoreText.text = "Score: " + currentScore; + if (scoreText != null) + { + scoreText.text = "Score: " + currentScore; + } + else + { + Debug.LogWarning("ScoreText chưa được kéo vào ScoreManager!"); + } } } diff --git a/Library/ArtifactDB b/Library/ArtifactDB index 4f63b53..4a8b3ff 100644 Binary files a/Library/ArtifactDB and b/Library/ArtifactDB differ