rope pull

This commit is contained in:
Sveske Juice 2024-02-03 21:27:35 -08:00
commit 629fe00866
13 changed files with 441 additions and 345 deletions

View File

@ -14,6 +14,7 @@ GameObject:
- component: {fileID: 5510899577631708383}
- component: {fileID: 4289092251764458493}
- component: {fileID: 3603265075407754381}
- component: {fileID: 7140252695900592518}
m_Layer: 0
m_Name: MainCamera
m_TagString: MainCamera
@ -118,7 +119,7 @@ MonoBehaviour:
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_RenderPostProcessing: 1
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
@ -187,7 +188,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Wave: 0
difficulty: 1
difficultyIncreasePerWave: 1
difficultyIncreasePerWave: 3
difficultyMultiplyDecreasePerWave: 0.05
WaveTime: 20
enemyDifficulties: []
@ -198,6 +199,66 @@ MonoBehaviour:
- {fileID: 0}
initialSpawnDelay: 5
enemyList: []
--- !u!114 &7140252695900592518
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2173372557174057003}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3}
m_Name:
m_EditorClassIdentifier:
volumeTrigger: {fileID: 8946450710138871461}
volumeLayer:
serializedVersion: 2
m_Bits: 257
stopNaNPropagation: 1
finalBlitToCameraTarget: 0
antialiasingMode: 0
temporalAntialiasing:
jitterSpread: 0.75
sharpness: 0.25
stationaryBlending: 0.95
motionBlending: 0.85
subpixelMorphologicalAntialiasing:
quality: 2
fastApproximateAntialiasing:
fastMode: 0
keepAlpha: 0
fog:
enabled: 1
excludeSkybox: 1
debugLayer:
lightMeter:
width: 512
height: 256
showCurves: 1
histogram:
width: 512
height: 256
channel: 3
waveform:
exposure: 0.12
height: 256
vectorscope:
size: 256
exposure: 0.12
overlaySettings:
linearDepth: 0
motionColorIntensity: 4
motionGridSize: 64
colorBlindnessType: 0
colorBlindnessStrength: 1
m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2}
m_ShowToolkit: 0
m_ShowCustomSorter: 0
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_AfterStackBundles: []
--- !u!1 &2607936989766580656
GameObject:
m_ObjectHideFlags: 0

View File

@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 3032075919872812610}
- component: {fileID: 6372697238776542044}
- component: {fileID: 1114532058491094574}
m_Layer: 0
m_Name: Managers
m_TagString: Untagged
@ -44,4 +45,16 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d07fc52b48ce953488ecef079872f5b7, type: 3}
m_Name:
m_EditorClassIdentifier:
audioLibrary: {fileID: 0}
audioLibrary: {fileID: 11400000, guid: 90a0ccefc407688499165286d0638124, type: 2}
--- !u!114 &1114532058491094574
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 809911508645467208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6cf314e58a8539a448e6ddeb3ad48149, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -11,6 +11,8 @@ GameObject:
- component: {fileID: 144529238244638330}
- component: {fileID: 7717684785049474632}
- component: {fileID: 901761791259710742}
- component: {fileID: 4976294692568481572}
- component: {fileID: 2066655509941542230}
m_Layer: 0
m_Name: Rope
m_TagString: Untagged
@ -169,3 +171,112 @@ LineRenderer:
m_UseWorldSpace: 1
m_Loop: 0
m_ApplyActiveColorSpace: 1
--- !u!114 &4976294692568481572
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5991265243222894942}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8766ad5393174fa488ef4a58b62181b4, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayTime: 1
--- !u!82 &2066655509941542230
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5991265243222894942}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: fd92966d4cde3244d9a711094cb947f6, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.107
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4

View File

@ -274,6 +274,9 @@ GameObject:
- component: {fileID: 1749848915408613053}
- component: {fileID: 1949941092232239315}
- component: {fileID: 1449424410418603396}
- component: {fileID: 8584374946327201457}
- component: {fileID: 2455289449300252362}
- component: {fileID: 3389629528887116870}
- component: {fileID: 1160419468000791564}
- component: {fileID: 1691493459240420355}
m_Layer: 7
@ -473,6 +476,21 @@ MonoBehaviour:
m_EditorClassIdentifier:
StepInterval: 0.8
Volume: 0.25
--- !u!114 &3389629528887116870
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3120938410244321186}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 20d294d88e5bc8a42afb1f72751fb61f, type: 3}
m_Name:
m_EditorClassIdentifier:
RopeRubleTolerance: 0.25
MaxVibration: 0.8
rope: {fileID: 0}
--- !u!1001 &6225877037457186740
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -190,6 +190,9 @@ GameObject:
- component: {fileID: 7071433868121438663}
- component: {fileID: 1949941092232239315}
- component: {fileID: 7729933180365677331}
- component: {fileID: 507903157909478597}
- component: {fileID: 3245702757494549198}
- component: {fileID: 5108819328747686001}
- component: {fileID: 8956099385762146752}
- component: {fileID: 5150961666696654592}
m_Layer: 7
@ -389,6 +392,21 @@ MonoBehaviour:
m_EditorClassIdentifier:
StepInterval: 0.8
Volume: 0.25
--- !u!114 &5108819328747686001
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3120938410244321186}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 20d294d88e5bc8a42afb1f72751fb61f, type: 3}
m_Name:
m_EditorClassIdentifier:
RopeRubleTolerance: 0.25
MaxVibration: 0.8
rope: {fileID: 0}
--- !u!1 &7787472247078384126
GameObject:
m_ObjectHideFlags: 0

View File

@ -1165,6 +1165,10 @@ PrefabInstance:
propertyPath: m_Name
value: Player2
objectReference: {fileID: 0}
- target: {fileID: 5108819328747686001, guid: 30e0cc55a67f02d4f92b2677ec4b1511, type: 3}
propertyPath: rope
value:
objectReference: {fileID: 1920006248}
- target: {fileID: 7071433868121438663, guid: 30e0cc55a67f02d4f92b2677ec4b1511, type: 3}
propertyPath: otherPlayerAttack
value:
@ -1468,6 +1472,10 @@ PrefabInstance:
propertyPath: m_Name
value: Player1
objectReference: {fileID: 0}
- target: {fileID: 3389629528887116870, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: rope
value:
objectReference: {fileID: 1920006248}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@ -3534,7 +3542,7 @@ MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7717684785049474632, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
m_PrefabInstance: {fileID: 4910321061857220295}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4910321061857220296}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3}
@ -3778,10 +3786,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6372697238776542044, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
propertyPath: audioLibrary
value:
objectReference: {fileID: 11400000, guid: 90a0ccefc407688499165286d0638124, type: 2}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@ -3853,128 +3857,8 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
insertIndex: -1
addedObject: {fileID: 4910321061857220297}
- targetCorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
insertIndex: -1
addedObject: {fileID: 4910321061857220300}
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
--- !u!1 &4910321061857220296 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5991265243222894942, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
m_PrefabInstance: {fileID: 4910321061857220295}
m_PrefabAsset: {fileID: 0}
--- !u!114 &4910321061857220297
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4910321061857220296}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8766ad5393174fa488ef4a58b62181b4, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayTime: 1
--- !u!82 &4910321061857220300
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4910321061857220296}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: fd92966d4cde3244d9a711094cb947f6, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.107
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &5796191506433166633
PrefabInstance:
m_ObjectHideFlags: 0
@ -3999,14 +3883,6 @@ PrefabInstance:
propertyPath: players.Array.data[1]
value:
objectReference: {fileID: 1579580564}
- target: {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
propertyPath: difficultyIncreasePerWave
value: 3
objectReference: {fileID: 0}
- target: {fileID: 5510899577631708383, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
propertyPath: m_RenderPostProcessing
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5959206239141280122, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
propertyPath: m_LocalPosition.x
value: 0
@ -4054,81 +3930,8 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 2173372557174057003, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
insertIndex: -1
addedObject: {fileID: 5796191506433166636}
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
--- !u!4 &5796191506433166634 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8946450710138871461, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
m_PrefabInstance: {fileID: 5796191506433166633}
m_PrefabAsset: {fileID: 0}
--- !u!1 &5796191506433166635 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2173372557174057003, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
m_PrefabInstance: {fileID: 5796191506433166633}
m_PrefabAsset: {fileID: 0}
--- !u!114 &5796191506433166636
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5796191506433166635}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3}
m_Name:
m_EditorClassIdentifier:
volumeTrigger: {fileID: 5796191506433166634}
volumeLayer:
serializedVersion: 2
m_Bits: 257
stopNaNPropagation: 1
finalBlitToCameraTarget: 0
antialiasingMode: 0
temporalAntialiasing:
jitterSpread: 0.75
sharpness: 0.25
stationaryBlending: 0.95
motionBlending: 0.85
subpixelMorphologicalAntialiasing:
quality: 2
fastApproximateAntialiasing:
fastMode: 0
keepAlpha: 0
fog:
enabled: 1
excludeSkybox: 1
debugLayer:
lightMeter:
width: 512
height: 256
showCurves: 1
histogram:
width: 512
height: 256
channel: 3
waveform:
exposure: 0.12
height: 256
vectorscope:
size: 256
exposure: 0.12
overlaySettings:
linearDepth: 0
motionColorIntensity: 4
motionGridSize: 64
colorBlindnessType: 0
colorBlindnessStrength: 1
m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2}
m_ShowToolkit: 0
m_ShowCustomSorter: 0
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_AfterStackBundles: []
--- !u!1001 &7693964683212020007
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -1,35 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class RumbleManager : MonoBehaviour
{
private Gamepad pad;
private Coroutine stopRumbleAfterTimeCorutine;
public void RumblePulse(float lowFrequency, float highFrequency, float duration, int player)
{
pad = Gamepad.all[player];
if (pad != null)
{
pad.SetMotorSpeeds(lowFrequency, highFrequency);
stopRumbleAfterTimeCorutine = StartCoroutine(stopRumble(duration, pad));
}
}
private IEnumerator stopRumble(float duration, Gamepad pad)
{
float elapsedTime = 0f;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
yield return null;
}
pad.SetMotorSpeeds(0f, 0f);
}
}

View File

@ -62,6 +62,9 @@ public class RopeSimulator : MonoBehaviour
[Header("Rendering")]
[SerializeField] LineRenderer lineRenderer;
[Header("Animaion")]
[SerializeField] float pullAnimationOvershootThreshold = 0.2f;
int[] order;
public float Overshoot => rope.CalculateLengthOvershoot();
@ -237,25 +240,26 @@ public class RopeSimulator : MonoBehaviour
float overshoot = rope.CalculateLengthOvershoot();
if (overshoot > 0)
{
float startDot = Vector2.Dot((start.position - rope.points[1].position).normalized, start.playerInput.movement);
Debug.Log($"player 1 dot: {startDot}");
if (startDot > 0.35f)
if (overshoot > pullAnimationOvershootThreshold)
{
start.playerAnimationHandler.animator.SetBool("IsPulling", true);
float startDot = Vector2.Dot((start.position - rope.points[1].position).normalized, start.playerInput.movement);
Debug.Log($"player 1 dot: {startDot}");
if (startDot > 0.35f)
{
start.playerAnimationHandler.animator.SetBool("IsPulling", true);
}
float endDot = Vector2.Dot((end.position - rope.points[rope.points.Count - 2].position).normalized, end.playerInput.movement);
Debug.Log($"player 2 dot: {endDot}");
if (endDot > 0.35f)
{
end.playerAnimationHandler.animator.SetBool("IsPulling", true);
}
}
else
{
start.playerAnimationHandler.animator.SetBool("IsPulling", false);
}
float endDot = Vector2.Dot((end.position - rope.points[rope.points.Count - 2].position).normalized, end.playerInput.movement);
Debug.Log($"player 2 dot: {endDot}");
if (endDot > 0.35f)
{
end.playerAnimationHandler.animator.SetBool("IsPulling", true);
}
else
{
end.playerAnimationHandler.animator.SetBool("IsPulling", false);
}

View File

@ -1,84 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerRumbling : MonoBehaviour
{
[SerializeField] private float RopeRubleTolerance = 0.5f;
private PlayerInput pInput;
private Gamepad pad;
// Rope
[SerializeField] private RopeSimulator rope;
private void Start()
{
Invoke("LateStart", 0.1f);
}
void LateStart()
{
pInput = GetComponent<PlayerInput>();
pad = Gamepad.all.ElementAtOrDefault(pInput.PlayerNum);
if (pad == null)
{
this.enabled = false;
}
hasInit = true;
}
bool hasInit = false;
private void Update()
{
if (!hasInit) return;
var rumble = new RumbleData();
float ropeClamed = Mathf.Max(0, rope.Overshoot);
if (ropeClamed > RopeRubleTolerance)
{
float mapped = ropeClamed.Remap(0.5f, 1f, 0f, 1f);
rumble.Max(mapped, mapped);
}
rumble.Commit(pad);
}
}
public class RumbleData
{
private bool modified = false;
private float lowFreq = 0;
private float highFreq = 0;
public void Max(float low, float high)
{
modified = true;
lowFreq = Mathf.Max(lowFreq, low);
highFreq = Mathf.Max(highFreq, high);
}
public void Min(float low, float high)
{
modified = true;
lowFreq = Mathf.Min(lowFreq, low);
highFreq = Mathf.Min(highFreq, high);
}
public void Add(float low, float high)
{
modified = true;
lowFreq += low;
highFreq += high;
}
public void Commit(Gamepad target)
{
modified = false;
target.SetMotorSpeeds(lowFreq, highFreq);
}
}

View File

@ -0,0 +1,48 @@
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
public class RopeRumbling : MonoBehaviour
{
[SerializeField] private float RopeRubleTolerance = 0.5f;
[SerializeField] private float MaxVibration = 0.8f;
private PlayerInput pInput;
private Gamepad pad;
// Rope
[SerializeField] private RopeSimulator rope;
private void Start()
{
Invoke("LateStart", 0.1f);
}
void LateStart()
{
pInput = GetComponent<PlayerInput>();
pad = Gamepad.all.ElementAtOrDefault(pInput.PlayerNum);
if (pad == null)
{
this.enabled = false;
}
else
{
}
hasInit = true;
}
bool hasInit = false;
private void Update()
{
if (!hasInit) return;
float ropeClamed = Mathf.Max(0, rope.Overshoot);
float sensitive_mapped = ropeClamed.Remap(0.2f, 1f, 0f, MaxVibration);
float mapped = ropeClamed.Remap(0.5f, 1f, 0f, MaxVibration);
RumbleManager.StartRumble(-1, sensitive_mapped, mapped, 0.1f);
}
}

View File

@ -0,0 +1,139 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class RumbleManager : MonoBehaviour
{
public static RumbleManager Instance { get; private set; }
public static Gamepad[] pads;
private class RumbleEffect
{
public float duration;
public float startTime;
public float lowFreq;
public float highFreq;
public RumbleEffect(float low, float high, float dur)
{
lowFreq = low;
highFreq = high;
duration = dur;
startTime = Time.time;
}
}
private static Dictionary<int, List<RumbleEffect>> playerRumbles = new Dictionary<int, List<RumbleEffect>>();
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
for (int i = 0; i < Gamepad.all.Count; i++)
{
playerRumbles[i] = new List<RumbleEffect>(); // Initialize list for each connected controller
}
}
else
{
Destroy(gameObject);
}
Invoke("LateStart", 0.1f);
}
void LateStart()
{
pads = Gamepad.all.ToArray();
initialized = true;
}
bool initialized = false;
private void Update()
{
if (!initialized) return;
foreach (var player in playerRumbles.Keys)
{
UpdateRumble(player);
}
}
private static void UpdateRumble(int player)
{
if (!playerRumbles.ContainsKey(player) || playerRumbles[player].Count == 0) return;
float maxLowFreq = 0f;
float maxHighFreq = 0f;
bool shouldRumble = false;
for (int i = playerRumbles[player].Count - 1; i >= 0; i--)
{
RumbleEffect effect = playerRumbles[player][i];
if (Time.time - effect.startTime >= effect.duration)
{
playerRumbles[player].RemoveAt(i);
}
else
{
shouldRumble = true;
maxLowFreq = Mathf.Max(maxLowFreq, effect.lowFreq);
maxHighFreq = Mathf.Max(maxHighFreq, effect.highFreq);
}
}
if (shouldRumble)
{
SetMotorSpeeds(player, maxLowFreq, maxHighFreq);
}
else
{
SetMotorSpeeds(player, 0, 0); // Stop rumbling for this player
}
}
// Now static, allowing it to be called without an instance
public static void StartRumble(int player, float lowFreq, float highFreq, float duration)
{
if (player == -1) // Target both players
{
foreach (var p in playerRumbles.Keys)
{
StartRumbleForPlayer(p, lowFreq, highFreq, duration);
}
}
else // Target a specific player
{
StartRumbleForPlayer(player, lowFreq, highFreq, duration);
}
}
private static void StartRumbleForPlayer(int player, float lowFreq, float highFreq, float duration)
{
if (!playerRumbles.ContainsKey(player))
{
playerRumbles[player] = new List<RumbleEffect>();
}
playerRumbles[player].Add(new RumbleEffect(lowFreq, highFreq, duration));
}
public static void StopAllRumbles(int player)
{
if (playerRumbles.ContainsKey(player))
{
playerRumbles[player].Clear();
SetMotorSpeeds(player, 0, 0); // Stop rumbling for this player
}
}
private static void SetMotorSpeeds(int player, float lowFreq, float highFreq)
{
if (player >= 0 && player < pads.Length)
{
pads[player].SetMotorSpeeds(lowFreq, highFreq);
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 89c1239a77bb4cc43b1a1552d271ab99
guid: 6cf314e58a8539a448e6ddeb3ad48149
MonoImporter:
externalObjects: {}
serializedVersion: 2