Skip to content

Commit

Permalink
fix: rubber force
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjae11 committed Dec 18, 2024
1 parent 8fee440 commit 1b99c02
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using PlasticGui.WorkspaceWindow.Configuration;
using UnityEngine;

namespace SWPPT3.SoftbodyPhysics
Expand Down Expand Up @@ -32,9 +33,7 @@ private void OnCollisionEnter(Collision collision)
{
if (contact.normal.y >= 0.7f)
{
Vector3 force = Vector3.up * (_rb.mass * rubberForce);
_rb.AddForce(force, ForceMode.Impulse);

_softbody.SetDirty = true;
break; // 하나라도 조건 만족하면 탈출
}
}
Expand Down
33 changes: 22 additions & 11 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ public void TriggerExit(Collider other)
private GameObject centerOfMasObj = null;
private Rigidbody _rbOfCenter = null;

public bool SetDirty;

private bool _isJumpKey;

public bool IsJumpKey
Expand All @@ -280,6 +282,7 @@ public bool IsJumpKey

private void Awake()
{
SetDirty = false;
Softness = _script.Softness;
Mass = _script.Mass;
PhysicsRoughness = _script.PhysicsRoughness;
Expand Down Expand Up @@ -538,7 +541,6 @@ public void FixJoint()
joint.xMotion = ConfigurableJointMotion.Locked;
joint.yMotion = ConfigurableJointMotion.Locked;
joint.zMotion = ConfigurableJointMotion.Locked;
joint.connectedAnchor = _bufferJointAnchors[i];
}
}

Expand All @@ -550,7 +552,6 @@ public void FreeJoint()
joint.xMotion = ConfigurableJointMotion.Limited;
joint.yMotion = ConfigurableJointMotion.Limited;
joint.zMotion = ConfigurableJointMotion.Limited;
joint.connectedAnchor = _oriJointAnchorArray[i];
}
}

Expand Down Expand Up @@ -649,15 +650,6 @@ public void Update()
}
}

if (PlayerStates == SoftStates.Rubber && _isJumpKey == true)
{
IsRubberJump = true;
}
else
{
IsRubberJump = false;
}

var setVertexUpdateJob = new SetVertexUpdateJob
{
LocalPositions = _optVerticesBuffer,
Expand Down Expand Up @@ -690,6 +682,25 @@ public void FixedUpdate()
var getConnectedAnchorHandle = getConnectedAnchorJob.Schedule(_jointsDictNa.Length,16, getVertexLocalPositionHandle);
getConnectedAnchorHandle.Complete();
}
if (PlayerStates == SoftStates.Rubber && _isJumpKey == true)
{
IsRubberJump = true;
}
else
{
IsRubberJump = false;
}

if (IsRubberJump && SetDirty)
{
SoftbodyJump(_script.RubberJump);
Invoke("ResetDirty", _script.ResetSec);
}
}

public void ResetDirty()
{
SetDirty = false;
}

public void OnDestroy()
Expand Down
4 changes: 3 additions & 1 deletion Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ public class SoftbodyScript : ScriptableObject
[SerializeField] private float damp;

[SerializeField] private float rubberJump;

[SerializeField] private float resetSec;
// [SerializeField] private float collissionSurfaceOffset;

public float Mass {get => mass; set => mass = value; }
public float PhysicsRoughness => physicsRoughness;
public float Softness => softness;
public float Damp => damp;
public float RubberJump => rubberJump;
// public float CollissionSurfaceOffset => collissionSurfaceOffset;
public float ResetSec => resetSec;


}
Expand Down

0 comments on commit 1b99c02

Please sign in to comment.