Skip to content

Commit 3b67453

Browse files
authored
Merge pull request #154 from leesiuuuu/feature/P2PTest
그랩 각도조절 문제 해결/ 그랩 중간에 각도조절 가능한 문제 해결
2 parents ae63ffc + 49274bd commit 3b67453

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

Assets/InputTest/InputPlayer.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ void Update()
112112

113113
if (PushGlove != null) PushGlove.PushPower = PushCharge;
114114

115-
if (GrabGlove != null && !GrabGlove.grabing) UpdateGrabRotation();
115+
if (GrabHeld && GrabGlove != null && !GrabGlove.grabing && !isGrabHolding)
116+
{
117+
isGrabHolding = true;
118+
RPressTime = Time.time;
119+
}
120+
121+
if (GrabGlove != null && !GrabGlove.grabing)
122+
UpdateGrabRotation();
116123

117124
if (jumpAble)
118125
{
@@ -338,12 +345,20 @@ public void OnPush(InputAction.CallbackContext context)
338345
public void OnGrab(InputAction.CallbackContext context)
339346
{
340347
if (!isLocalPlayer) return;
348+
341349
if (context.started)
342350
{
343351
GrabHeld = true;
344-
isGrabHolding = true;
345-
RPressTime = Time.time;
346-
if (GrabObject != null) GrabObject.rotation = Quaternion.Euler(0f, 0f, 0f);
352+
353+
// 그랩이 이미 돌아와 있으면 바로 회전 가능
354+
if (GrabGlove != null && !GrabGlove.grabing)
355+
{
356+
isGrabHolding = true;
357+
RPressTime = Time.time;
358+
359+
if (GrabObject != null)
360+
GrabObject.rotation = Quaternion.Euler(0f, 0f, 0f);
361+
}
347362
}
348363
else if (context.canceled)
349364
{
@@ -383,12 +398,14 @@ private void UpdateGrabRotation()
383398
world.z = GrabObject.position.z;
384399

385400
Vector3 dirWorld = world - GrabObject.position;
386-
Vector3 dirLocal = transform.InverseTransformDirection(dirWorld);
387401

388-
if (dirLocal.sqrMagnitude > 0.0001f)
402+
if (dirWorld.sqrMagnitude > 0.0001f)
389403
{
390-
float rawLocalAngle = Mathf.Atan2(dirLocal.y, dirLocal.x) * Mathf.Rad2Deg;
391-
float desiredLocal = Mathf.Clamp(rawLocalAngle, -Mathf.Abs(maxAngle), Mathf.Abs(maxAngle));
404+
float facingSign = flip ? -1f : 1f;
405+
float adjustedX = dirWorld.x * facingSign;
406+
407+
float desiredLocal = Mathf.Atan2(dirWorld.y, adjustedX) * Mathf.Rad2Deg;
408+
desiredLocal = Mathf.Clamp(desiredLocal, -Mathf.Abs(maxAngle), Mathf.Abs(maxAngle));
392409
float currentLocalZ = GrabObject.localEulerAngles.z;
393410
float smoothLocalZ = Mathf.LerpAngle(currentLocalZ, desiredLocal, Time.deltaTime * aimSmooth);
394411
GrabObject.localRotation = Quaternion.Euler(0f, 0f, smoothLocalZ);

0 commit comments

Comments
 (0)