Bouncing effect + music sync
This commit is contained in:
parent
493b027f3a
commit
cd837472b9
|
|
@ -293,7 +293,7 @@ MonoBehaviour:
|
|||
- 0
|
||||
- 1.007976
|
||||
- 2.9457881
|
||||
- 3.2396343
|
||||
- 3.239634
|
||||
- 3.535689
|
||||
- 3.7529073
|
||||
- 4.945534
|
||||
|
|
@ -356,9 +356,12 @@ MonoBehaviour:
|
|||
- 42.154396
|
||||
- 42.503956
|
||||
line: {fileID: 1026138248}
|
||||
offsetMultipliers: {x: 1, y: 1}
|
||||
offsetMultipliers: {x: 1.05, y: 0.77}
|
||||
objectToMove: {fileID: 1120561245}
|
||||
source: {fileID: 861733210}
|
||||
audioOffset: 0.05
|
||||
MoveCmd: 0
|
||||
bouncingIntensity: 0.65
|
||||
--- !u!4 &335227241
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -374,6 +377,134 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &861733209
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 861733211}
|
||||
- component: {fileID: 861733210}
|
||||
m_Layer: 0
|
||||
m_Name: src
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!82 &861733210
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 861733209}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: f87294eb4bca5f24f80fa7ff9c9e9c4e, type: 3}
|
||||
m_PlayOnAwake: 1
|
||||
m_Volume: 1
|
||||
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!4 &861733211
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 861733209}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1026138247
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -435,70 +566,70 @@ LineRenderer:
|
|||
m_SortingOrder: 0
|
||||
m_Positions:
|
||||
- {x: 0, y: 0, z: 0}
|
||||
- {x: 1.007976, y: -1.007976, z: 0}
|
||||
- {x: 2.9457881, y: 0.92983603, z: 0}
|
||||
- {x: 3.2396343, y: 0.6359899, z: 0}
|
||||
- {x: 3.535689, y: 0.93204474, z: 0}
|
||||
- {x: 3.7529073, y: 0.7148266, z: 0}
|
||||
- {x: 4.945534, y: 1.9074535, z: 0}
|
||||
- {x: 5.2670794, y: 1.5859084, z: 0}
|
||||
- {x: 5.5404615, y: 1.8592906, z: 0}
|
||||
- {x: 5.838297, y: 1.5614552, z: 0}
|
||||
- {x: 8.023146, y: 3.746304, z: 0}
|
||||
- {x: 9.277683, y: 2.4917665, z: 0}
|
||||
- {x: 9.612368, y: 2.8264508, z: 0}
|
||||
- {x: 9.978131, y: 2.4606872, z: 0}
|
||||
- {x: 11.05203, y: 3.5345855, z: 0}
|
||||
- {x: 11.563883, y: 3.0227323, z: 0}
|
||||
- {x: 11.862214, y: 3.3210635, z: 0}
|
||||
- {x: 12.16262, y: 3.020658, z: 0}
|
||||
- {x: 13.06958, y: 3.9276185, z: 0}
|
||||
- {x: 13.596535, y: 3.4006639, z: 0}
|
||||
- {x: 13.906741, y: 3.7108703, z: 0}
|
||||
- {x: 16.131954, y: 1.4856572, z: 0}
|
||||
- {x: 17.358862, y: 2.712565, z: 0}
|
||||
- {x: 17.68974, y: 2.3816876, z: 0}
|
||||
- {x: 17.955818, y: 2.6477666, z: 0}
|
||||
- {x: 18.111351, y: 2.4922338, z: 0}
|
||||
- {x: 18.661879, y: 3.0427613, z: 0}
|
||||
- {x: 19.170216, y: 2.5344243, z: 0}
|
||||
- {x: 19.696922, y: 3.061131, z: 0}
|
||||
- {x: 20.262955, y: 2.4950986, z: 0}
|
||||
- {x: 20.802982, y: 3.0351262, z: 0}
|
||||
- {x: 21.02081, y: 2.8172994, z: 0}
|
||||
- {x: 21.289953, y: 3.0864434, z: 0}
|
||||
- {x: 21.832458, y: 2.5439382, z: 0}
|
||||
- {x: 22.291527, y: 3.0030065, z: 0}
|
||||
- {x: 23.767723, y: 1.5268102, z: 0}
|
||||
- {x: 24.27649, y: 2.0355763, z: 0}
|
||||
- {x: 25.550953, y: 0.7611127, z: 0}
|
||||
- {x: 25.946125, y: 1.1562848, z: 0}
|
||||
- {x: 26.332308, y: 0.770102, z: 0}
|
||||
- {x: 26.837963, y: 1.2757573, z: 0}
|
||||
- {x: 27.237825, y: 0.875895, z: 0}
|
||||
- {x: 27.88322, y: 1.5212903, z: 0}
|
||||
- {x: 28.390924, y: 1.0135865, z: 0}
|
||||
- {x: 29.355066, y: 1.9777284, z: 0}
|
||||
- {x: 29.900814, y: 1.4319806, z: 0}
|
||||
- {x: 30.385643, y: 1.9168096, z: 0}
|
||||
- {x: 32.436077, y: -0.13362455, z: 0}
|
||||
- {x: 33.891426, y: 1.3217244, z: 0}
|
||||
- {x: 34.48847, y: 0.72468233, z: 0}
|
||||
- {x: 34.974228, y: 1.2104421, z: 0}
|
||||
- {x: 35.49399, y: 0.6906781, z: 0}
|
||||
- {x: 36.081886, y: 1.2785726, z: 0}
|
||||
- {x: 36.373074, y: 0.9873853, z: 0}
|
||||
- {x: 36.975796, y: 1.5901074, z: 0}
|
||||
- {x: 37.52076, y: 1.0451436, z: 0}
|
||||
- {x: 37.923553, y: 1.4479375, z: 0}
|
||||
- {x: 38.40126, y: 0.9702306, z: 0}
|
||||
- {x: 39.078022, y: 1.6469922, z: 0}
|
||||
- {x: 39.528507, y: 1.196507, z: 0}
|
||||
- {x: 40.53657, y: 2.2045712, z: 0}
|
||||
- {x: 41.026608, y: 1.7145352, z: 0}
|
||||
- {x: 41.505398, y: 2.1933255, z: 0}
|
||||
- {x: 42.154396, y: 1.5443273, z: 0}
|
||||
- {x: 42.503956, y: 1.893887, z: 0}
|
||||
- {x: 1.0583748, y: -0.7761415, z: 0}
|
||||
- {x: 3.0930774, y: 0.71597373, z: 0}
|
||||
- {x: 3.4016156, y: 0.48971242, z: 0}
|
||||
- {x: 3.7124734, y: 0.71767485, z: 0}
|
||||
- {x: 3.9405525, y: 0.5504169, z: 0}
|
||||
- {x: 5.1928105, y: 1.4687396, z: 0}
|
||||
- {x: 5.530433, y: 1.2211499, z: 0}
|
||||
- {x: 5.8174844, y: 1.4316542, z: 0}
|
||||
- {x: 6.1302114, y: 1.202321, z: 0}
|
||||
- {x: 8.424302, y: 2.8846545, z: 0}
|
||||
- {x: 9.741567, y: 1.9186606, z: 0}
|
||||
- {x: 10.092985, y: 2.1763675, z: 0}
|
||||
- {x: 10.477037, y: 1.8947295, z: 0}
|
||||
- {x: 11.60463, y: 2.7216313, z: 0}
|
||||
- {x: 12.1420765, y: 2.3275044, z: 0}
|
||||
- {x: 12.455324, y: 2.5572195, z: 0}
|
||||
- {x: 12.77075, y: 2.3259072, z: 0}
|
||||
- {x: 13.723059, y: 3.0242667, z: 0}
|
||||
- {x: 14.2763605, y: 2.6185117, z: 0}
|
||||
- {x: 14.6020775, y: 2.8573706, z: 0}
|
||||
- {x: 16.93855, y: 1.1439567, z: 0}
|
||||
- {x: 18.226805, y: 2.0886755, z: 0}
|
||||
- {x: 18.574224, y: 1.8339, z: 0}
|
||||
- {x: 18.85361, y: 2.0387807, z: 0}
|
||||
- {x: 19.016918, y: 1.9190204, z: 0}
|
||||
- {x: 19.59497, y: 2.3429267, z: 0}
|
||||
- {x: 20.128725, y: 1.9515072, z: 0}
|
||||
- {x: 20.681768, y: 2.3570714, z: 0}
|
||||
- {x: 21.276102, y: 1.9212265, z: 0}
|
||||
- {x: 21.84313, y: 2.3370478, z: 0}
|
||||
- {x: 22.071848, y: 2.169321, z: 0}
|
||||
- {x: 22.35445, y: 2.3765619, z: 0}
|
||||
- {x: 22.92408, y: 1.9588329, z: 0}
|
||||
- {x: 23.406101, y: 2.3123155, z: 0}
|
||||
- {x: 24.956108, y: 1.1756444, z: 0}
|
||||
- {x: 25.490313, y: 1.5673944, z: 0}
|
||||
- {x: 26.828499, y: 0.58605736, z: 0}
|
||||
- {x: 27.24343, y: 0.8903399, z: 0}
|
||||
- {x: 27.648922, y: 0.5929792, z: 0}
|
||||
- {x: 28.17986, y: 0.9823338, z: 0}
|
||||
- {x: 28.599716, y: 0.67443985, z: 0}
|
||||
- {x: 29.27738, y: 1.1713942, z: 0}
|
||||
- {x: 29.810469, y: 0.7804623, z: 0}
|
||||
- {x: 30.822819, y: 1.5228516, z: 0}
|
||||
- {x: 31.395853, y: 1.1026258, z: 0}
|
||||
- {x: 31.904924, y: 1.4759442, z: 0}
|
||||
- {x: 34.05788, y: -0.10289007, z: 0}
|
||||
- {x: 35.585995, y: 1.0177286, z: 0}
|
||||
- {x: 36.21289, y: 0.55800617, z: 0}
|
||||
- {x: 36.72294, y: 0.93204117, z: 0}
|
||||
- {x: 37.26869, y: 0.5318229, z: 0}
|
||||
- {x: 37.88598, y: 0.9845016, z: 0}
|
||||
- {x: 38.191727, y: 0.7602874, z: 0}
|
||||
- {x: 38.824585, y: 1.2243835, z: 0}
|
||||
- {x: 39.396797, y: 0.80476135, z: 0}
|
||||
- {x: 39.81973, y: 1.1149126, z: 0}
|
||||
- {x: 40.321323, y: 0.7470783, z: 0}
|
||||
- {x: 41.03192, y: 1.2681848, z: 0}
|
||||
- {x: 41.504932, y: 0.92131114, z: 0}
|
||||
- {x: 42.563396, y: 1.6975206, z: 0}
|
||||
- {x: 43.077934, y: 1.3201929, z: 0}
|
||||
- {x: 43.580666, y: 1.6888615, z: 0}
|
||||
- {x: 44.262115, y: 1.1891328, z: 0}
|
||||
- {x: 44.62915, y: 1.4582938, z: 0}
|
||||
m_Parameters:
|
||||
serializedVersion: 3
|
||||
widthMultiplier: 0.1
|
||||
|
|
@ -651,7 +782,7 @@ Transform:
|
|||
m_GameObject: {fileID: 1120561245}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 25.9953, y: 1.1970692, z: 0}
|
||||
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
|
|
@ -665,3 +796,4 @@ SceneRoots:
|
|||
- {fileID: 1026138249}
|
||||
- {fileID: 335227241}
|
||||
- {fileID: 1120561247}
|
||||
- {fileID: 861733211}
|
||||
|
|
|
|||
124
Assets/Scripts/EasingFunctions.cs
Normal file
124
Assets/Scripts/EasingFunctions.cs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
|
||||
namespace Kryz.Tweening
|
||||
{
|
||||
// Made with the help of this great post: https://joshondesign.com/2013/03/01/improvedEasingEquations
|
||||
|
||||
// --------------------------------- Other Related Links --------------------------------------------------------------------
|
||||
// Original equations, bad formulation: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js
|
||||
// A few equations, very simplified: https://gist.github.com/gre/1650294
|
||||
// Easings.net equations, simplified: https://github.com/ai/easings.net/blob/master/src/easings/easingsFunctions.ts
|
||||
|
||||
public static class EasingFunctions
|
||||
{
|
||||
public static float Linear(float t) => t;
|
||||
|
||||
public static float InQuad(float t) => t * t;
|
||||
public static float OutQuad(float t) => 1 - InQuad(1 - t);
|
||||
public static float InOutQuad(float t)
|
||||
{
|
||||
if (t < 0.5) return InQuad(t * 2) / 2;
|
||||
return 1 - InQuad((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InCubic(float t) => t * t * t;
|
||||
public static float OutCubic(float t) => 1 - InCubic(1 - t);
|
||||
public static float InOutCubic(float t)
|
||||
{
|
||||
if (t < 0.5) return InCubic(t * 2) / 2;
|
||||
return 1 - InCubic((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InQuart(float t) => t * t * t * t;
|
||||
public static float OutQuart(float t) => 1 - InQuart(1 - t);
|
||||
public static float InOutQuart(float t)
|
||||
{
|
||||
if (t < 0.5) return InQuart(t * 2) / 2;
|
||||
return 1 - InQuart((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InQuint(float t) => t * t * t * t * t;
|
||||
public static float OutQuint(float t) => 1 - InQuint(1 - t);
|
||||
public static float InOutQuint(float t)
|
||||
{
|
||||
if (t < 0.5) return InQuint(t * 2) / 2;
|
||||
return 1 - InQuint((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InSine(float t) => 1 - (float)Math.Cos(t * Math.PI / 2);
|
||||
public static float OutSine(float t) => (float)Math.Sin(t * Math.PI / 2);
|
||||
public static float InOutSine(float t) => (float)(Math.Cos(t * Math.PI) - 1) / -2;
|
||||
|
||||
public static float InExpo(float t) => (float)Math.Pow(2, 10 * (t - 1));
|
||||
public static float OutExpo(float t) => 1 - InExpo(1 - t);
|
||||
public static float InOutExpo(float t)
|
||||
{
|
||||
if (t < 0.5) return InExpo(t * 2) / 2;
|
||||
return 1 - InExpo((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InCirc(float t) => -((float)Math.Sqrt(1 - t * t) - 1);
|
||||
public static float OutCirc(float t) => 1 - InCirc(1 - t);
|
||||
public static float InOutCirc(float t)
|
||||
{
|
||||
if (t < 0.5) return InCirc(t * 2) / 2;
|
||||
return 1 - InCirc((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InElastic(float t) => 1 - OutElastic(1 - t);
|
||||
public static float OutElastic(float t)
|
||||
{
|
||||
float p = 0.3f;
|
||||
return (float)Math.Pow(2, -10 * t) * (float)Math.Sin((t - p / 4) * (2 * Math.PI) / p) + 1;
|
||||
}
|
||||
public static float InOutElastic(float t)
|
||||
{
|
||||
if (t < 0.5) return InElastic(t * 2) / 2;
|
||||
return 1 - InElastic((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InBack(float t)
|
||||
{
|
||||
float s = 1.70158f;
|
||||
return t * t * ((s + 1) * t - s);
|
||||
}
|
||||
public static float OutBack(float t) => 1 - InBack(1 - t);
|
||||
public static float InOutBack(float t)
|
||||
{
|
||||
if (t < 0.5) return InBack(t * 2) / 2;
|
||||
return 1 - InBack((1 - t) * 2) / 2;
|
||||
}
|
||||
|
||||
public static float InBounce(float t) => 1 - OutBounce(1 - t);
|
||||
public static float OutBounce(float t)
|
||||
{
|
||||
float div = 2.75f;
|
||||
float mult = 7.5625f;
|
||||
|
||||
if (t < 1 / div)
|
||||
{
|
||||
return mult * t * t;
|
||||
}
|
||||
else if (t < 2 / div)
|
||||
{
|
||||
t -= 1.5f / div;
|
||||
return mult * t * t + 0.75f;
|
||||
}
|
||||
else if (t < 2.5 / div)
|
||||
{
|
||||
t -= 2.25f / div;
|
||||
return mult * t * t + 0.9375f;
|
||||
}
|
||||
else
|
||||
{
|
||||
t -= 2.625f / div;
|
||||
return mult * t * t + 0.984375f;
|
||||
}
|
||||
}
|
||||
public static float InOutBounce(float t)
|
||||
{
|
||||
if (t < 0.5) return InBounce(t * 2) / 2;
|
||||
return 1 - InBounce((1 - t) * 2) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EasingFunctions.cs.meta
Normal file
11
Assets/Scripts/EasingFunctions.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 762943c0218e5804c878a0ed4c351836
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements.Experimental;
|
||||
|
||||
public class AlgorithmTest : MonoBehaviour
|
||||
{
|
||||
|
|
@ -8,7 +9,8 @@ public class AlgorithmTest : MonoBehaviour
|
|||
public LineRenderer line;
|
||||
public Vector2 offsetMultipliers = Vector2.one;
|
||||
public GameObject objectToMove; // The GameObject to move
|
||||
|
||||
public AudioSource source;
|
||||
public float audioOffset = 0.05f;
|
||||
private Vector3[] points;
|
||||
|
||||
|
||||
|
|
@ -16,20 +18,24 @@ public class AlgorithmTest : MonoBehaviour
|
|||
|
||||
|
||||
Coroutine movingCoroutine;
|
||||
void OnDrawGizmos(){
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
RegenerateLines();
|
||||
|
||||
if(MoveCmd){
|
||||
if (MoveCmd)
|
||||
{
|
||||
MoveCmd = false;
|
||||
if(movingCoroutine!= null){StopCoroutine(movingCoroutine);}
|
||||
if (movingCoroutine != null) { StopCoroutine(movingCoroutine); }
|
||||
movingCoroutine = StartCoroutine(MoveAlongPath());
|
||||
}
|
||||
}
|
||||
|
||||
void RegenerateLines(){
|
||||
void RegenerateLines()
|
||||
{
|
||||
points = new Vector3[allHits.Count];
|
||||
|
||||
for (int i = 0; i < points.Length; i++) {
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i] = GetPosition(i);
|
||||
}
|
||||
|
||||
|
|
@ -37,35 +43,45 @@ public class AlgorithmTest : MonoBehaviour
|
|||
line.SetPositions(points);
|
||||
}
|
||||
|
||||
Vector3 GetPosition(int index) {
|
||||
void Update(){
|
||||
objectToMove.transform.position = GetPositionAtTime(source.time + audioOffset);
|
||||
}
|
||||
|
||||
Vector3 GetPosition(int index)
|
||||
{
|
||||
float hitX = allHits[index];
|
||||
|
||||
float diff = 0;
|
||||
float prevY = 0;
|
||||
|
||||
// Calculate diff and prevY if the index is greater than 0
|
||||
if (index > 0) {
|
||||
if (index > 0)
|
||||
{
|
||||
diff = allHits[index] - allHits[index - 1];
|
||||
prevY = points[index - 1].y; // Use the already calculated point to avoid recursion
|
||||
}
|
||||
|
||||
float flipSide = index % 2 == 0 ? 1 : -1;
|
||||
float y = prevY + (flipSide * diff);
|
||||
float y = prevY + (flipSide * diff * offsetMultipliers.y);
|
||||
|
||||
return new Vector3(hitX * offsetMultipliers.x, y, 0);
|
||||
}
|
||||
|
||||
// Call this function to start moving the GameObject along the path
|
||||
public void StartMovement() {
|
||||
if (objectToMove != null && points != null && points.Length > 1) {
|
||||
public void StartMovement()
|
||||
{
|
||||
if (objectToMove != null && points != null && points.Length > 1)
|
||||
{
|
||||
StartCoroutine(MoveAlongPath());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator MoveAlongPath() {
|
||||
float timer=0;
|
||||
while(timer < allHits[allHits.Count-1]){
|
||||
timer +=Time.deltaTime;
|
||||
private IEnumerator MoveAlongPath()
|
||||
{
|
||||
float timer = 0;
|
||||
while (timer < allHits[allHits.Count - 1])
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
objectToMove.transform.position = GetPositionAtTime(timer);
|
||||
}
|
||||
|
|
@ -77,46 +93,42 @@ public class AlgorithmTest : MonoBehaviour
|
|||
// yield return StartCoroutine(MoveFromTo(objectToMove, startPoint, endPoint, duration));
|
||||
// }
|
||||
}
|
||||
|
||||
private IEnumerator MoveFromTo(GameObject obj, Vector3 start, Vector3 end, float duration) {
|
||||
float elapsedTime = 0;
|
||||
|
||||
while (elapsedTime < duration) {
|
||||
obj.transform.position = Vector3.Lerp(start, end, elapsedTime / duration);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
obj.transform.position = end;
|
||||
}
|
||||
public Vector3 GetPositionAtTime(float time) {
|
||||
if (points == null || points.Length < 2) {
|
||||
public float bouncingIntensity = 0.5f;
|
||||
public Vector3 GetPositionAtTime(float time)
|
||||
{
|
||||
if (points == null || points.Length < 2)
|
||||
{
|
||||
return Vector3.zero; // Return zero if points are not set up
|
||||
}
|
||||
|
||||
// If the time is before the first hit, return the first position
|
||||
if (time <= allHits[0]) {
|
||||
if (time <= allHits[0])
|
||||
{
|
||||
return points[0];
|
||||
}
|
||||
|
||||
// If the time is after the last hit, return the last position
|
||||
if (time >= allHits[allHits.Count - 1]) {
|
||||
if (time >= allHits[allHits.Count - 1])
|
||||
{
|
||||
return points[points.Length - 1];
|
||||
}
|
||||
|
||||
// Find the current segment based on the given time
|
||||
for (int i = 0; i < allHits.Count - 1; i++) {
|
||||
if (time >= allHits[i] && time < allHits[i + 1]) {
|
||||
for (int i = 0; i < allHits.Count - 1; i++)
|
||||
{
|
||||
if (time >= allHits[i] && time < allHits[i + 1])
|
||||
{
|
||||
Vector3 startPoint = points[i];
|
||||
Vector3 endPoint = points[i + 1];
|
||||
float segmentDuration = allHits[i + 1] - allHits[i];
|
||||
float t = (time - allHits[i]) / segmentDuration;
|
||||
|
||||
return Vector3.Lerp(startPoint, endPoint, t);
|
||||
|
||||
return Vector3.Lerp(startPoint, endPoint, Mathf.Pow(t,bouncingIntensity));
|
||||
}
|
||||
}
|
||||
|
||||
return Vector3.zero; // Return zero if no valid segment is found (should not happen)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user