Skip to content

Commit

Permalink
Merge pull request #88 from 2024FALL-SWPP/feature/finalsoftbody
Browse files Browse the repository at this point in the history
Feature/finalsoftbody
  • Loading branch information
yeonjae11 authored Dec 17, 2024
2 parents e2870bf + 4b8af39 commit 5fd5446
Show file tree
Hide file tree
Showing 21 changed files with 52,098 additions and 103 deletions.
50,715 changes: 50,715 additions & 0 deletions Assets/SWPPT3/Scenes/Test Scene 1.unity

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Assets/SWPPT3/Scenes/Test Scene 1.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/SWPPT3/Scripts/Main/Main.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c",
"Unity.TextMeshPro"
"Unity.TextMeshPro",
"GUID:db246dbf6515fd646b6f91b91d98c213"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
34 changes: 16 additions & 18 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SWPPT3.Main.Prop;
using UnityEngine.InputSystem;
using SWPPT3.Main.PlayerLogic.State;
using SWPPT3.SoftbodyPhysics;

namespace SWPPT3.Main.PlayerLogic
{
Expand All @@ -15,37 +16,25 @@ public class Player : MonoBehaviour
private int slimeCount , metalCount, rubberCount;
public Dictionary<PlayerStates, int> Item;

public event Action OnItemChanged;
private SoftbodyGenerator _softbody;

[SerializeField]
private Rigidbody _rb;
// [SerializeField]
public PhysicMaterial _physicMaterial;
[SerializeField]
public Collider _collider;
public event Action OnItemChanged;

private PlayerState PlayerState => _playerStates[_currentState];

public PlayerStates CurrentState => _currentState;

public Rigidbody Rigidbody => _rb;

private readonly Dictionary<PlayerStates, PlayerState> _playerStates = new()
{
{ PlayerStates.Metal, new MetalState() },
{ PlayerStates.Rubber, new RubberState() },
{ PlayerStates.Slime, new SlimeState() },
};
public void SetBounciness(float bounciness, PhysicMaterialCombine bounceCombine = PhysicMaterialCombine.Maximum)
{
_physicMaterial.bounciness = bounciness;
_physicMaterial.bounceCombine = bounceCombine;

_collider.material = _physicMaterial;
}

private void Awake()
{
_softbody = GetComponent<SoftbodyGenerator>();
if (Item == null)
{
Item = new Dictionary<PlayerStates, int>
Expand All @@ -67,9 +56,18 @@ public void TryChangeState(PlayerStates newState)
if (newState != PlayerStates.Slime) Item[newState]--;
OnItemChanged?.Invoke();
_currentState = newState;
PlayerState.ChangeRigidbody(_rb);
PlayerState.ChangePhysics(_collider, _physicMaterial);
_collider.hasModifiableContacts = newState == PlayerStates.Slime;
if (newState == PlayerStates.Rubber)
{
_softbody.SetRubberJump();
}
else if (newState == PlayerStates.Metal)
{
_softbody.SetMetal();
}
else if (newState == PlayerStates.Slime)
{
_softbody.SetSlime();
}
}

Debug.Log(_currentState);
Expand Down
20 changes: 12 additions & 8 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SWPPT3.Main.Manager;
using SWPPT3.Main.PlayerLogic.State;
using SWPPT3.Main.Prop;
using SWPPT3.SoftbodyPhysics;
using Unity.Collections;
using UnityEngine;

Expand All @@ -11,8 +12,8 @@ namespace SWPPT3.Main.PlayerLogic
public class PlayerMover : MonoBehaviour
{
[SerializeField] private PlayerScript _playerScript;
[SerializeField] private Player _player;
[SerializeField] private Rigidbody _rb;
private Player _player;
private SoftbodyGenerator _softbody;

private float _moveSpeed;
private float _jumpForce;
Expand All @@ -31,9 +32,12 @@ public class PlayerMover : MonoBehaviour

private void Start()
{
_player = GetComponent<Player>();
_softbody = GetComponent<SoftbodyGenerator>();

_moveSpeed = _playerScript.MoveSpeed;
_rotationSpeed = _playerScript.RotationSpeed;
_jumpForce = _playerScript.JumpForce * _rb.mass;
_jumpForce = _playerScript.JumpForce;
_isHoldingJump = false;
_playerTransform = transform;
if (InputManager.Instance != null)
Expand All @@ -54,15 +58,15 @@ private void Update()
{
Vector3 moveDirection = GetMoveDirection();
Vector3 force = moveDirection * _moveSpeed;
_rb.AddForce(force, ForceMode.VelocityChange);
_softbody.move(force);

if (isRightButton && _lookInput != Vector2.zero)
{
RotatePlayer();
}
if (_player.CurrentState == PlayerStates.Rubber && _groundedObjects.Count == 0 && _isHoldingJump)
{
_player.SetBounciness(1.0f);
// _player.SetBounciness(1.0f);
}
}

Expand Down Expand Up @@ -126,12 +130,12 @@ private void HandleJump()
{
if (_groundedObjects.Count > 0 && GameManager.Instance.GameState == GameState.Playing)
{
_rb.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse);
_softbody.SoftbodyJump(_jumpForce);
}
_isHoldingJump = true;
if (_player.CurrentState == PlayerStates.Rubber)
{
_player.SetBounciness(1.0f);
// _player.SetBounciness(1.0f);
}
}

Expand All @@ -140,7 +144,7 @@ private void HandleJumpCancel()
_isHoldingJump = false;
if (_player.CurrentState == PlayerStates.Rubber)
{
_player.SetBounciness(0.5f);
// _player.SetBounciness(0.5f);
}
}

Expand Down
16 changes: 0 additions & 16 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/State/MetalState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,5 @@ public override void InteractWithProp(Player player, PropBase obstacle)
base.InteractWithProp(player, obstacle);
}
}

public override void ChangeRigidbody(Rigidbody rb)
{

}

public override void ChangePhysics(Collider collider, PhysicMaterial physicMaterial)
{
physicMaterial.bounciness = 0f;
physicMaterial.dynamicFriction = 0f;
physicMaterial.staticFriction = 0f;

physicMaterial.bounceCombine = PhysicMaterialCombine.Maximum;

collider.material = physicMaterial;
}
}
}
3 changes: 0 additions & 3 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/State/PlayerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public virtual void StopInteractWithProp(Player player, PropBase obstacle)
obstacle.StopInteractWithPlayer(player.CurrentState);

}

public abstract void ChangeRigidbody(Rigidbody rb);
public abstract void ChangePhysics(Collider collider, PhysicMaterial physicMaterial);
}

}
14 changes: 0 additions & 14 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/State/RubberState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,5 @@ public override void InteractWithProp(Player player, PropBase obstacle)
base.InteractWithProp(player, obstacle);
}
}
public override void ChangeRigidbody(Rigidbody rb)
{

}
public override void ChangePhysics(Collider collider, PhysicMaterial physicMaterial)
{
physicMaterial.bounciness = 0.5f;
physicMaterial.dynamicFriction = 0f;
physicMaterial.staticFriction = 0f;

physicMaterial.bounceCombine = PhysicMaterialCombine.Maximum;

collider.material = physicMaterial;
}
}
}
14 changes: 0 additions & 14 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/State/SlimeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,5 @@ public override void InteractWithProp(Player player, PropBase obstacle)
base.InteractWithProp(player, obstacle);
}
}
public override void ChangeRigidbody(Rigidbody rb)
{

}
public override void ChangePhysics(Collider collider, PhysicMaterial physicMaterial)
{
physicMaterial.bounciness = 0f;
physicMaterial.dynamicFriction = 0f;
physicMaterial.staticFriction = 0f;

physicMaterial.bounceCombine = PhysicMaterialCombine.Maximum;

collider.material = physicMaterial;
}
}
}
18 changes: 18 additions & 0 deletions Assets/SWPPT3/Scripts/Main/ScriptableObjects/SoftbodyScript.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1473d3df9778433e9c9a8f1015f8a109, type: 3}
m_Name: SoftbodyScript
m_EditorClassIdentifier:
mass: 2
physicsRoughness: 2
softness: 2
damp: 0.5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using UnityEngine;

namespace SWPPT3.SoftbodyPhysics
{
public class RubberJump : MonoBehaviour
{
private Rigidbody _rb;

private void Awake()
{
_rb = GetComponent<Rigidbody>();
}

private void OnCollisionEnter(Collision collision)
{
// foreach (ContactPoint contact in collision.contacts)
// {
// if (contact.normal.y >= 0.7f)
// {
// Vector3 jumpForce = Vector3.up * (_rb.mass * 30f);
// _rb.AddForce(jumpForce, ForceMode.Impulse);
//
// Debug.Log($"Applied Jump Force: {jumpForce} at Contact Point Normal: {contact.normal}");
// break; // 하나라도 조건 만족하면 탈출
// }
// }
}
}
}
3 changes: 3 additions & 0 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5fd5446

Please sign in to comment.