bad camera movement

This commit is contained in:
Rapandrasmus 2023-07-14 01:40:33 +02:00
parent 34f6be44d6
commit f5fe0d7895
4 changed files with 361 additions and 16564 deletions

View file

@ -1037,9 +1037,13 @@ MonoBehaviour:
EligibleHits: [] EligibleHits: []
scheduledInputs: [] scheduledInputs: []
firstEnable: 0 firstEnable: 0
startCameraMoveLength: 3
elephantRef: {fileID: -5564384145903586768, guid: b3040fc162a3d6342971f82026e4335f, type: 3} elephantRef: {fileID: -5564384145903586768, guid: b3040fc162a3d6342971f82026e4335f, type: 3}
elephantDistance: 10.304 elephantDistance: 10.304
elephantStart: 0.004 elephantStart: 0.004
elephantHangCameraMoveLength: 2
elephantHangMaxDip: 1
elephantReleaseMoveLength: 6
giraffeRef: {fileID: 5248028064811562821, guid: 72e69b6337a6bc04f86ffcf5bcedab92, type: 3} giraffeRef: {fileID: 5248028064811562821, guid: 72e69b6337a6bc04f86ffcf5bcedab92, type: 3}
giraffeDistance: 0 giraffeDistance: 0
giraffeStart: 0 giraffeStart: 0

View file

@ -5,15 +5,15 @@ using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_AnimalAcrobat namespace HeavenStudio.Games.Scripts_AnimalAcrobat
{ {
public enum ObstacleType
{
Elephant,
Giraffe,
Monkeys,
Monkey
}
public class AcrobatObstacle : MonoBehaviour public class AcrobatObstacle : MonoBehaviour
{ {
private enum ObstacleType
{
Elephant,
Giraffe,
Monkeys,
Monkey
}
[Header("Properties")] [Header("Properties")]
[SerializeField] private float holdLength = 2f; [SerializeField] private float holdLength = 2f;
[SerializeField] private float fullRotateAngle = 120f; [SerializeField] private float fullRotateAngle = 120f;
@ -69,13 +69,16 @@ namespace HeavenStudio.Games.Scripts_AnimalAcrobat
{ {
float normalizedSwingBeat = cond.GetPositionFromBeat(startBeat, holdLength); float normalizedSwingBeat = cond.GetPositionFromBeat(startBeat, holdLength);
float negativeOffset = (normalizedSwingBeat < 0) ? -1 : 0; float negativeOffset = (normalizedSwingBeat < 0) ? -1 : 0;
float normalizedAdjusted = Mathf.Abs(normalizedSwingBeat % 1);
if ((Mathf.Floor(normalizedSwingBeat) + negativeOffset) % 2 == 0) if ((Mathf.Floor(normalizedSwingBeat) + negativeOffset) % 2 == 0)
{ {
rotatePivot.localEulerAngles = new Vector3(0, 0, func(-halfAngle, halfAngle, Mathf.Abs(normalizedSwingBeat % 1))); rotatePivot.localEulerAngles = new Vector3(0, 0, func(-halfAngle, halfAngle, normalizedAdjusted));
if (type == ObstacleType.Monkeys) anim.DoNormalizedAnimation("WhiteMonkeysSwing", normalizedAdjusted);
} }
else else
{ {
rotatePivot.localEulerAngles = new Vector3(0, 0, func(halfAngle, -halfAngle, Mathf.Abs(normalizedSwingBeat % 1))); rotatePivot.localEulerAngles = new Vector3(0, 0, func(halfAngle, -halfAngle, normalizedAdjusted));
if (type == ObstacleType.Monkeys) anim.DoNormalizedAnimation("WhiteMonkeysSwing", 1 - normalizedAdjusted);
} }
} }
} }

View file

@ -41,12 +41,18 @@ namespace HeavenStudio.Games.Loaders
namespace HeavenStudio.Games namespace HeavenStudio.Games
{ {
using HeavenStudio.Games.Scripts_AnimalAcrobat;
using HeavenStudio.Util;
public class AnimalAcrobat : Minigame public class AnimalAcrobat : Minigame
{ {
[SerializeField] private float startCameraMoveLength = 3f;
[Header("Elephant")] [Header("Elephant")]
[SerializeField] private AcrobatObstacle elephantRef; [SerializeField] private AcrobatObstacle elephantRef;
[SerializeField] private float elephantDistance; [SerializeField] private float elephantDistance;
[SerializeField] private float elephantStart = 0.004f; [SerializeField] private float elephantStart = 0.004f;
[SerializeField] private float elephantHangCameraMoveLength = 2f;
[SerializeField] private float elephantHangMaxDip = 1f;
[SerializeField] private float elephantReleaseMoveLength = 3f;
[Header("Giraffe")] [Header("Giraffe")]
[SerializeField] private AcrobatObstacle giraffeRef; [SerializeField] private AcrobatObstacle giraffeRef;
[SerializeField] private float giraffeDistance; [SerializeField] private float giraffeDistance;
@ -60,13 +66,144 @@ namespace HeavenStudio.Games
[SerializeField] private float oneMonkeyDistance; [SerializeField] private float oneMonkeyDistance;
[SerializeField] private float oneMonkeyStart; [SerializeField] private float oneMonkeyStart;
private struct QueuedObstacleCameraMove
{
public double startBeat;
public ObstacleType type;
public float GetLength()
{
return type switch
{
ObstacleType.Elephant => 4f,
ObstacleType.Giraffe => 8f,
ObstacleType.Monkeys => 5f,
ObstacleType.Monkey => 3f,
_ => throw new System.NotImplementedException(),
};
}
public float GetHoldLength()
{
return type switch
{
ObstacleType.Elephant => 2f,
ObstacleType.Giraffe => 4f,
ObstacleType.Monkeys => 3f,
ObstacleType.Monkey => 1f,
_ => throw new System.NotImplementedException(),
};
}
}
private int movesIndex = 0;
private List<QueuedObstacleCameraMove> moves = new();
private Vector3 lastCameraPos = new Vector3(0, 0, 0);
private EasingFunction.Function funcInOut;
private EasingFunction.Function funcIn;
private EasingFunction.Function funcOut;
public static AnimalAcrobat instance; public static AnimalAcrobat instance;
private void Awake() private void Awake()
{ {
instance = this; instance = this;
funcInOut = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseInOutQuad);
funcIn = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseInQuad);
funcOut = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseOutQuad);
} }
private void LateUpdate()
{
var cond = Conductor.instance;
if (cond.isPlaying && !cond.isPaused)
{
CameraMoveUpdate(cond);
}
}
private void CameraMoveUpdate(Conductor cond)
{
if (movesIndex >= moves.Count) return;
var currentMove = moves[movesIndex];
double songBeat = cond.songPositionInBeats;
if (cond.songPositionInBeats > currentMove.startBeat + currentMove.GetLength())
{
lastCameraPos = GameCamera.additionalPosition;
movesIndex++;
CameraMoveUpdate(cond);
return;
}
if (movesIndex == 0 && songBeat >= currentMove.startBeat - 1 && songBeat < currentMove.startBeat)
{
float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat - 1, 1);
float newPosX = Mathf.Lerp(lastCameraPos.x, startCameraMoveLength, normalizedBeat);
GameCamera.additionalPosition = new Vector3(newPosX, 0, 0);
}
else if (songBeat >= currentMove.startBeat && songBeat < currentMove.startBeat + currentMove.GetHoldLength())
{
float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat, currentMove.GetHoldLength());
float newPosX = 0;
float newPosY = 0;
switch (currentMove.type)
{
case ObstacleType.Elephant:
if (movesIndex == 0) newPosX = funcInOut(lastCameraPos.x + startCameraMoveLength, lastCameraPos.x + startCameraMoveLength + elephantHangCameraMoveLength, normalizedBeat);
else newPosX = funcInOut(lastCameraPos.x, lastCameraPos.x + elephantHangCameraMoveLength, normalizedBeat);
if (normalizedBeat <= 0.5f)
{
float normalizedIn = cond.GetPositionFromBeat(currentMove.startBeat, 1);
newPosY = funcIn(0, -elephantHangMaxDip, normalizedIn);
}
else
{
float normalizedOut = cond.GetPositionFromBeat(currentMove.startBeat + 1, 1);
newPosY = funcOut(-elephantHangMaxDip, 0, normalizedOut);
}
break;
case ObstacleType.Giraffe:
break;
case ObstacleType.Monkeys:
break;
case ObstacleType.Monkey:
break;
default: break;
}
GameCamera.additionalPosition = new Vector3(newPosX, newPosY, 0);
}
else if (songBeat >= currentMove.startBeat + currentMove.GetHoldLength())
{
float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat + currentMove.GetHoldLength(), currentMove.GetLength() - currentMove.GetHoldLength());
float newPosX = 0;
float newPosY = 0;
switch (currentMove.type)
{
case ObstacleType.Elephant:
if (movesIndex == 0)
{
float baseValue = lastCameraPos.x + startCameraMoveLength + elephantHangCameraMoveLength;
newPosX = Mathf.Lerp(baseValue, baseValue + elephantReleaseMoveLength, normalizedBeat);
}
else
{
float baseValue = lastCameraPos.x + elephantHangCameraMoveLength;
newPosX = Mathf.Lerp(baseValue, baseValue + elephantReleaseMoveLength, normalizedBeat);
}
break;
case ObstacleType.Giraffe:
break;
case ObstacleType.Monkeys:
break;
case ObstacleType.Monkey:
break;
default: break;
}
GameCamera.additionalPosition = new Vector3(newPosX, newPosY, 0);
}
}
#region Spawn Animals
public override void OnPlay(double beat) public override void OnPlay(double beat)
{ {
SpawnAnimals(beat); SpawnAnimals(beat);
@ -92,52 +229,85 @@ namespace HeavenStudio.Games
"animalAcrobat/monkeyShort" => oneMonkeyStart - oneMonkeyDistance, "animalAcrobat/monkeyShort" => oneMonkeyStart - oneMonkeyDistance,
_ => throw new System.NotImplementedException() _ => throw new System.NotImplementedException()
}; };
double nextGameSwitchBeat = double.MaxValue;
var allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }).FindAll(x => x.beat > gameSwitchBeat);
if (allEnds.Count > 0) nextGameSwitchBeat = allEnds[0].beat;
foreach (var animal in animalEvents) foreach (var animal in animalEvents)
{ {
if (animal.beat == nextBeat) if (animal.beat != nextBeat || animal.beat + animal.length <= gameSwitchBeat || animal.beat > nextGameSwitchBeat) continue;
nextBeat += animal.length;
switch (animal.datamodel)
{ {
nextBeat += animal.length; case "animalAcrobat/elephant":
switch (animal.datamodel) startPos += elephantDistance;
{ AcrobatObstacle spawnedElephant = Instantiate(elephantRef, transform);
case "animalAcrobat/elephant": spawnedElephant.transform.position = new Vector3(startPos, 0, 0);
startPos += elephantDistance; spawnedElephant.Init(animal.beat, gameSwitchBeat);
AcrobatObstacle spawnedElephant = Instantiate(elephantRef, transform); moves.Add(new QueuedObstacleCameraMove
spawnedElephant.transform.position = new Vector3(startPos, 0, 0); {
spawnedElephant.Init(animal.beat, gameSwitchBeat); startBeat = animal.beat,
break; type = ObstacleType.Elephant
case "animalAcrobat/giraffe": });
startPos += giraffeDistance; break;
AcrobatObstacle spawnedGiraffe = Instantiate(giraffeRef, transform); case "animalAcrobat/giraffe":
spawnedGiraffe.transform.position = new Vector3(startPos, 0, 0); startPos += giraffeDistance;
spawnedGiraffe.Init(animal.beat, gameSwitchBeat); AcrobatObstacle spawnedGiraffe = Instantiate(giraffeRef, transform);
break; spawnedGiraffe.transform.position = new Vector3(startPos, 0, 0);
case "animalAcrobat/monkeys": spawnedGiraffe.Init(animal.beat, gameSwitchBeat);
startPos += monkeysDistance; moves.Add(new QueuedObstacleCameraMove
AcrobatObstacle spawnedMonkeyLong = Instantiate(monkeysRef, transform); {
spawnedMonkeyLong.transform.position = new Vector3(startPos, 0, 0); startBeat = animal.beat,
spawnedMonkeyLong.Init(animal.beat, gameSwitchBeat); type = ObstacleType.Giraffe
startPos += oneMonkeyDistance; });
AcrobatObstacle spawnedOneMonkeyS = Instantiate(oneMonkeyRef, transform); break;
spawnedOneMonkeyS.transform.position = new Vector3(startPos, 0, 0); case "animalAcrobat/monkeys":
spawnedOneMonkeyS.Init(animal.beat, gameSwitchBeat); startPos += monkeysDistance;
break; AcrobatObstacle spawnedMonkeyLong = Instantiate(monkeysRef, transform);
case "animalAcrobat/monkeyLong": spawnedMonkeyLong.transform.position = new Vector3(startPos, 0, 0);
startPos += monkeysDistance; spawnedMonkeyLong.Init(animal.beat, gameSwitchBeat);
AcrobatObstacle spawnedMonkeys = Instantiate(monkeysRef, transform); moves.Add(new QueuedObstacleCameraMove
spawnedMonkeys.transform.position = new Vector3(startPos, 0, 0); {
spawnedMonkeys.Init(animal.beat, gameSwitchBeat); startBeat = animal.beat,
break; type = ObstacleType.Monkeys
case "animalAcrobat/monkeyShort": });
startPos += oneMonkeyDistance; startPos += oneMonkeyDistance;
AcrobatObstacle spawnedOneMonkey = Instantiate(oneMonkeyRef, transform); AcrobatObstacle spawnedOneMonkeyS = Instantiate(oneMonkeyRef, transform);
spawnedOneMonkey.transform.position = new Vector3(startPos, 0, 0); spawnedOneMonkeyS.transform.position = new Vector3(startPos, 0, 0);
spawnedOneMonkey.Init(animal.beat, gameSwitchBeat); spawnedOneMonkeyS.Init(animal.beat + 5, gameSwitchBeat);
break; moves.Add(new QueuedObstacleCameraMove
default: break; {
} startBeat = animal.beat + 5,
type = ObstacleType.Monkey
});
break;
case "animalAcrobat/monkeyLong":
startPos += monkeysDistance;
AcrobatObstacle spawnedMonkeys = Instantiate(monkeysRef, transform);
spawnedMonkeys.transform.position = new Vector3(startPos, 0, 0);
spawnedMonkeys.Init(animal.beat, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
startBeat = animal.beat,
type = ObstacleType.Monkeys
});
break;
case "animalAcrobat/monkeyShort":
startPos += oneMonkeyDistance;
AcrobatObstacle spawnedOneMonkey = Instantiate(oneMonkeyRef, transform);
spawnedOneMonkey.transform.position = new Vector3(startPos, 0, 0);
spawnedOneMonkey.Init(animal.beat, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
startBeat = animal.beat,
type = ObstacleType.Monkey
});
break;
default: break;
} }
} }
} }
#endregion
} }
} }