Skip to content

Commit

Permalink
update physics
Browse files Browse the repository at this point in the history
  • Loading branch information
SantyWang committed Jul 7, 2024
1 parent 49f7ab9 commit 4e02c93
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 5 deletions.
170 changes: 169 additions & 1 deletion Assets/Prefabs/Barrier Spawner.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 1074448275808737555}
- component: {fileID: 1812875468374849642}
- component: {fileID: 206478226315688279}
- component: {fileID: 4245626130367110183}
m_Layer: 8
m_Name: WoodenBarbedWireBarrier_33_v1
m_TagString: Barrier
Expand Down Expand Up @@ -121,6 +122,33 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &4245626130367110183
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1579014642673645766}
serializedVersion: 4
m_Mass: 50
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &2439459965191426395
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -134,6 +162,7 @@ GameObject:
- component: {fileID: 3374600650123314083}
- component: {fileID: 6319197797048684620}
- component: {fileID: 9201439254696262158}
- component: {fileID: 2264461840318196387}
m_Layer: 8
m_Name: BarbedWireMetalFence_26_v1
m_TagString: Barrier
Expand Down Expand Up @@ -242,6 +271,33 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &2264461840318196387
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2439459965191426395}
serializedVersion: 4
m_Mass: 10
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &4155857151116016207
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -255,6 +311,7 @@ GameObject:
- component: {fileID: 2498493386552957850}
- component: {fileID: 3850010191295810255}
- component: {fileID: 5583489516514593272}
- component: {fileID: 1537866279243339173}
m_Layer: 8
m_Name: WoodenBarrier_09_v1
m_TagString: Barrier
Expand Down Expand Up @@ -346,7 +403,7 @@ MeshCollider:
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 5
m_Convex: 0
m_Convex: 1
m_CookingOptions: 30
m_Mesh: {fileID: -8430925605481246473, guid: c15c8257712a538499f0877d29e23f41, type: 3}
--- !u!114 &5583489516514593272
Expand All @@ -363,6 +420,33 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &1537866279243339173
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4155857151116016207}
serializedVersion: 4
m_Mass: 50
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &4563174049369110232
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -376,6 +460,7 @@ GameObject:
- component: {fileID: 3409027095777258949}
- component: {fileID: 2644154014692233776}
- component: {fileID: 4665948785085631260}
- component: {fileID: 3956531213341213814}
m_Layer: 8
m_Name: BarbedWireFence_36_v1
m_TagString: Barrier
Expand Down Expand Up @@ -483,6 +568,33 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &3956531213341213814
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4563174049369110232}
serializedVersion: 4
m_Mass: 20
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &5610237183853628697
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -558,6 +670,7 @@ GameObject:
- component: {fileID: 9214471075522204820}
- component: {fileID: 7503548104344994219}
- component: {fileID: 1417621251563924871}
- component: {fileID: 5519857047636918765}
m_Layer: 8
m_Name: SingleLog_09_v1
m_TagString: Barrier
Expand Down Expand Up @@ -667,6 +780,33 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &5519857047636918765
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7268982350081652033}
serializedVersion: 4
m_Mass: 10
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &7793178408440083269
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -680,6 +820,7 @@ GameObject:
- component: {fileID: 7793178408440083387}
- component: {fileID: 7793178408440083386}
- component: {fileID: 6116931823450244694}
- component: {fileID: 6724402269860907975}
m_Layer: 8
m_Name: ConcreteBarrier_08_v2
m_TagString: Barrier
Expand Down Expand Up @@ -788,3 +929,30 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveDirection: {x: 1, y: 0, z: 0}
movingSpeed: 1
--- !u!54 &6724402269860907975
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7793178408440083269}
serializedVersion: 4
m_Mass: 50
m_Drag: 0
m_AngularDrag: 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: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
6 changes: 3 additions & 3 deletions Assets/Scripts/BarrierController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class BarrierController : MonoBehaviour

void Start()
{
//rigidBody = GetComponent<Rigidbody>();
rigidBody = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
transform.position += moveDirection * movingSpeed * Time.deltaTime;
//rigidBody.MovePosition(transform.position + moveDirection * movingSpeed * Time.deltaTime);
//transform.position += moveDirection * movingSpeed * Time.deltaTime;
rigidBody.MovePosition(transform.position + moveDirection * movingSpeed * Time.deltaTime);

if (transform.position.y < -300)
{
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/GameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class GameMode : MonoBehaviour
private CrateSpawner crateSpawner;
[HideInInspector]
public bool isGameRunning = false;
public float deadZone = -7;

private GameObject playerStart1;
private GameObject playerStart2;
Expand Down
31 changes: 30 additions & 1 deletion Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class PlayerController : MonoBehaviour
private Animator animator;
private AudioSystem audioSystem;
public Rigidbody rigidBody;
GameMode gameMode;
bool grounded = false;


Expand All @@ -52,12 +53,13 @@ void Start()
{
AddCrate();
}
gameMode = GameObject.Find("GameMode").GetComponent<GameMode>();
}

void endGame()
{
animator.SetBool("fail", true);
GameObject.Find("GameMode").GetComponent<GameMode>().StopGame();
gameMode.StopGame();
}

private bool disableUserInput = false;
Expand All @@ -72,6 +74,33 @@ void Update()
{
return;
}

if (transform.position.x < gameMode.deadZone)
{
transform.position -= transform.forward * gameMode.deadZone;

if (allCarriedCrates.Count > 3)
{
var newCount = allCarriedCrates.Count - 3;
allCarriedCrates.ForEach(crate =>
{
Object.Destroy(crate);
});
allCarriedCrates.Clear();
for (int i = 0; i < newCount; i++)
{
AddCrate();
}
}
else
{
endGame();
}
}
if (transform.position.y < -10)
{
endGame();
}
//GROUNDED
if (Physics.Raycast(transform.position + new Vector3(0.1f, 0.1f, 0.1f), Vector3.down, 0.15f)
|| Physics.Raycast(transform.position + new Vector3(0.1f, 0.1f, -0.1f), Vector3.down, 0.15f)
Expand Down

0 comments on commit 4e02c93

Please sign in to comment.