Skip to content

Commit

Permalink
Merge pull request #103 from 2024FALL-SWPP/player_move
Browse files Browse the repository at this point in the history
fix: slime cannot push boxes
  • Loading branch information
gjwj5505 authored Dec 18, 2024
2 parents 6ac7860 + acfdc95 commit 7b29bc5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 60 deletions.
52 changes: 27 additions & 25 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void OnEnable()
{
_player = GetComponent<Player>();
_softbody = GetComponent<SoftbodyGenerator>();
Physics.ContactModifyEvent += ModificationEvent;
//Physics.ContactModifyEvent += ModificationEvent;
if(_softbody != null)
{
_softbody.HandleCollisionEnterEvent += HandleCollisionEnter;
Expand All @@ -86,7 +86,7 @@ public void OnEnable()

public void OnDisable()
{
Physics.ContactModifyEvent -= ModificationEvent;
//Physics.ContactModifyEvent -= ModificationEvent;
if (_softbody != null)
{
_softbody.HandleCollisionEnterEvent -= HandleCollisionEnter;
Expand All @@ -97,29 +97,31 @@ public void OnDisable()
}
}

public void ModificationEvent(PhysicsScene scene, NativeArray<ModifiableContactPair> pairs)
{
for (int i = 0; i < pairs.Length; i++)
{
var pair = pairs[i];
var properties = pair.massProperties;

if(_rigidBodyId == pair.bodyInstanceID)
{
properties.otherInverseMassScale = 0f;
properties.otherInverseInertiaScale = 0f;
}
if(_rigidBodyId == pair.otherBodyInstanceID)
{
properties.inverseMassScale = 0f;
properties.inverseInertiaScale = 0f;
}

pair.massProperties = properties;

pairs[i] = pair;
}
}
// public void ModificationEvent(PhysicsScene scene, NativeArray<ModifiableContactPair> pairs)
// {
// Debug.Log("modify : playermover");
// for (int i = 0; i < pairs.Length; i++)
// {
// var pair = pairs[i];
// var properties = pair.massProperties;
// Debug.Log(_rigidBodyId.ToString() + " " + pair.bodyInstanceID.ToString() + " " + pair.otherBodyInstanceID.ToString());

// if(_rigidBodyId == pair.bodyInstanceID)
// {
// properties.otherInverseMassScale = 0f;
// properties.otherInverseInertiaScale = 0f;
// }
// if(_rigidBodyId == pair.otherBodyInstanceID)
// {
// properties.inverseMassScale = 0f;
// properties.inverseInertiaScale = 0f;
// }

// pair.massProperties = properties;

// pairs[i] = pair;
// }
// }


private Vector3 GetMoveDirection()
Expand Down
33 changes: 17 additions & 16 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/Softbody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ private void OnDestroy()

private void OnEnable()
{
Physics.ContactModifyEvent += ModificationEvent;
//Physics.ContactModifyEvent += ModificationEvent;
}

private void OnDisable()
{
Physics.ContactModifyEvent -= ModificationEvent;
//Physics.ContactModifyEvent -= ModificationEvent;
}

public void SetHasModifiableContacts(bool enabled)
Expand All @@ -421,23 +421,24 @@ public void SetHasModifiableContacts(bool enabled)
}
}

public void ModificationEvent(PhysicsScene scene, NativeArray<ModifiableContactPair> pairs)
{
for (int i = 0; i < pairs.Length; i++)
{
var pair = pairs[i];
// public void ModificationEvent(PhysicsScene scene, NativeArray<ModifiableContactPair> pairs)
// {
// Debug.Log("modify : softbody");
// for (int i = 0; i < pairs.Length; i++)
// {
// var pair = pairs[i];

var properties = pair.massProperties;
properties.inverseMassScale = 1f;
properties.inverseInertiaScale = 1f;
properties.otherInverseMassScale = 0f;
properties.otherInverseInertiaScale = 0f;
// var properties = pair.massProperties;
// properties.inverseMassScale = 1f;
// properties.inverseInertiaScale = 1f;
// properties.otherInverseMassScale = 0f;
// properties.otherInverseInertiaScale = 0f;

pair.massProperties = properties;
// pair.massProperties = properties;

pairs[i] = pair;
}
}
// pairs[i] = pair;
// }
// }

[BurstCompile]
private struct GetBonePositionJob : IJobParallelForTransform
Expand Down
45 changes: 26 additions & 19 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SoftbodyGenerator : MonoBehaviour

private List<Rigidbody> _rigidbodyList = new List<Rigidbody>();
private Rigidbody[] _rigidbodyArray;
private HashSet<int> _rigidbodyIdSet = new HashSet<int>();

private Rigidbody rootRB;

Expand Down Expand Up @@ -220,13 +221,18 @@ public void ModificationEvent(PhysicsScene scene, NativeArray<ModifiableContactP
for (int i = 0; i < pairs.Length; i++)
{
var pair = pairs[i];

var properties = pair.massProperties;

properties.inverseMassScale = 1f;
properties.inverseInertiaScale = 1f;
properties.otherInverseMassScale = 0;
properties.otherInverseInertiaScale = 0;
if(_rigidbodyIdSet.Contains(pair.bodyInstanceID))
{
properties.otherInverseMassScale = 0f;
properties.otherInverseInertiaScale = 0f;
}
if(_rigidbodyIdSet.Contains(pair.otherBodyInstanceID))
{
properties.inverseMassScale = 0f;
properties.inverseInertiaScale = 0f;
}

pair.massProperties = properties;

Expand Down Expand Up @@ -382,6 +388,8 @@ private void Awake()
rubberJump.rubberForce = _script.RubberJump;

_rigidbodyList.Add(_tempRigidBody);
_rigidbodyIdSet.Add(_tempRigidBody.GetInstanceID());
Debug.Log(_tempRigidBody.GetInstanceID());

_tempObj.AddComponent<DebugColorGameObject>().Color = Random.ColorHSV();

Expand Down Expand Up @@ -564,25 +572,24 @@ public void SetSlime()
if (PlayerStates != SoftStates.Slime)
{
FreeJoint();
foreach (var sc in _sphereColliderArray)
{
sc.hasModifiableContacts = true;
}
}

foreach (var sc in _sphereColliderArray)
{
Debug.Log("hasmodifiablaContacts true");
sc.hasModifiableContacts = true;
}
PlayerStates = SoftStates.Slime;

}

public void SetMetal()
{
if (PlayerStates == SoftStates.Slime)
{
FixJoint();
foreach (var sc in _sphereColliderArray)
{
sc.hasModifiableContacts = false;
}
}
foreach (var sc in _sphereColliderArray)
{
sc.hasModifiableContacts = false;
}

PlayerStates = SoftStates.Metal;
Expand All @@ -593,10 +600,10 @@ public void SetRubber()
if (PlayerStates == SoftStates.Slime)
{
FixJoint();
foreach (var sc in _sphereColliderArray)
{
sc.hasModifiableContacts = false;
}
}
foreach (var sc in _sphereColliderArray)
{
sc.hasModifiableContacts = false;
}

PlayerStates = SoftStates.Rubber;
Expand Down

0 comments on commit 7b29bc5

Please sign in to comment.