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: []
scheduledInputs: []
firstEnable: 0
startCameraMoveLength: 3
elephantRef: {fileID: -5564384145903586768, guid: b3040fc162a3d6342971f82026e4335f, type: 3}
elephantDistance: 10.304
elephantStart: 0.004
elephantHangCameraMoveLength: 2
elephantHangMaxDip: 1
elephantReleaseMoveLength: 6
giraffeRef: {fileID: 5248028064811562821, guid: 72e69b6337a6bc04f86ffcf5bcedab92, type: 3}
giraffeDistance: 0
giraffeStart: 0

View file

@ -5,15 +5,15 @@ using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_AnimalAcrobat
{
public enum ObstacleType
{
Elephant,
Giraffe,
Monkeys,
Monkey
}
public class AcrobatObstacle : MonoBehaviour
{
private enum ObstacleType
{
Elephant,
Giraffe,
Monkeys,
Monkey
}
[Header("Properties")]
[SerializeField] private float holdLength = 2f;
[SerializeField] private float fullRotateAngle = 120f;
@ -69,13 +69,16 @@ namespace HeavenStudio.Games.Scripts_AnimalAcrobat
{
float normalizedSwingBeat = cond.GetPositionFromBeat(startBeat, holdLength);
float negativeOffset = (normalizedSwingBeat < 0) ? -1 : 0;
float normalizedAdjusted = Mathf.Abs(normalizedSwingBeat % 1);
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
{
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
{
using HeavenStudio.Games.Scripts_AnimalAcrobat;
using HeavenStudio.Util;
public class AnimalAcrobat : Minigame
{
[SerializeField] private float startCameraMoveLength = 3f;
[Header("Elephant")]
[SerializeField] private AcrobatObstacle elephantRef;
[SerializeField] private float elephantDistance;
[SerializeField] private float elephantStart = 0.004f;
[SerializeField] private float elephantHangCameraMoveLength = 2f;
[SerializeField] private float elephantHangMaxDip = 1f;
[SerializeField] private float elephantReleaseMoveLength = 3f;
[Header("Giraffe")]
[SerializeField] private AcrobatObstacle giraffeRef;
[SerializeField] private float giraffeDistance;
@ -60,13 +66,144 @@ namespace HeavenStudio.Games
[SerializeField] private float oneMonkeyDistance;
[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;
private void Awake()
{
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)
{
SpawnAnimals(beat);
@ -91,53 +228,86 @@ namespace HeavenStudio.Games
"animalAcrobat/monkeyLong" => monkeysStart - monkeysDistance,
"animalAcrobat/monkeyShort" => oneMonkeyStart - oneMonkeyDistance,
_ => 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)
{
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;
switch (animal.datamodel)
{
case "animalAcrobat/elephant":
startPos += elephantDistance;
AcrobatObstacle spawnedElephant = Instantiate(elephantRef, transform);
spawnedElephant.transform.position = new Vector3(startPos, 0, 0);
spawnedElephant.Init(animal.beat, gameSwitchBeat);
break;
case "animalAcrobat/giraffe":
startPos += giraffeDistance;
AcrobatObstacle spawnedGiraffe = Instantiate(giraffeRef, transform);
spawnedGiraffe.transform.position = new Vector3(startPos, 0, 0);
spawnedGiraffe.Init(animal.beat, gameSwitchBeat);
break;
case "animalAcrobat/monkeys":
startPos += monkeysDistance;
AcrobatObstacle spawnedMonkeyLong = Instantiate(monkeysRef, transform);
spawnedMonkeyLong.transform.position = new Vector3(startPos, 0, 0);
spawnedMonkeyLong.Init(animal.beat, gameSwitchBeat);
startPos += oneMonkeyDistance;
AcrobatObstacle spawnedOneMonkeyS = Instantiate(oneMonkeyRef, transform);
spawnedOneMonkeyS.transform.position = new Vector3(startPos, 0, 0);
spawnedOneMonkeyS.Init(animal.beat, gameSwitchBeat);
break;
case "animalAcrobat/monkeyLong":
startPos += monkeysDistance;
AcrobatObstacle spawnedMonkeys = Instantiate(monkeysRef, transform);
spawnedMonkeys.transform.position = new Vector3(startPos, 0, 0);
spawnedMonkeys.Init(animal.beat, gameSwitchBeat);
break;
case "animalAcrobat/monkeyShort":
startPos += oneMonkeyDistance;
AcrobatObstacle spawnedOneMonkey = Instantiate(oneMonkeyRef, transform);
spawnedOneMonkey.transform.position = new Vector3(startPos, 0, 0);
spawnedOneMonkey.Init(animal.beat, gameSwitchBeat);
break;
default: break;
}
case "animalAcrobat/elephant":
startPos += elephantDistance;
AcrobatObstacle spawnedElephant = Instantiate(elephantRef, transform);
spawnedElephant.transform.position = new Vector3(startPos, 0, 0);
spawnedElephant.Init(animal.beat, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
startBeat = animal.beat,
type = ObstacleType.Elephant
});
break;
case "animalAcrobat/giraffe":
startPos += giraffeDistance;
AcrobatObstacle spawnedGiraffe = Instantiate(giraffeRef, transform);
spawnedGiraffe.transform.position = new Vector3(startPos, 0, 0);
spawnedGiraffe.Init(animal.beat, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
startBeat = animal.beat,
type = ObstacleType.Giraffe
});
break;
case "animalAcrobat/monkeys":
startPos += monkeysDistance;
AcrobatObstacle spawnedMonkeyLong = Instantiate(monkeysRef, transform);
spawnedMonkeyLong.transform.position = new Vector3(startPos, 0, 0);
spawnedMonkeyLong.Init(animal.beat, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
startBeat = animal.beat,
type = ObstacleType.Monkeys
});
startPos += oneMonkeyDistance;
AcrobatObstacle spawnedOneMonkeyS = Instantiate(oneMonkeyRef, transform);
spawnedOneMonkeyS.transform.position = new Vector3(startPos, 0, 0);
spawnedOneMonkeyS.Init(animal.beat + 5, gameSwitchBeat);
moves.Add(new QueuedObstacleCameraMove
{
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
}
}