From 592420abacfb5840db2075bb93ddca5f983090d9 Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Tue, 20 Jun 2023 15:55:47 +0200 Subject: [PATCH] Fixed rotate BattleAnimation & enddelay... EndDelay for BattleAnimations is now correctly calculated Rotate BattleAnimation now actually ends when it's done rotating --- P3D/Battle/BattleAnimations/BAEntityRotate.vb | 63 +++++++++++-------- .../BattleAnimations/BattleAnimation3D.vb | 10 ++- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/P3D/Battle/BattleAnimations/BAEntityRotate.vb b/P3D/Battle/BattleAnimations/BAEntityRotate.vb index 1f4ce8420..049069b12 100644 --- a/P3D/Battle/BattleAnimations/BAEntityRotate.vb +++ b/P3D/Battle/BattleAnimations/BAEntityRotate.vb @@ -9,6 +9,8 @@ Dim ReturnVector As Vector3 Dim hasReturned As Boolean = False Dim DoRotation As Vector3 = New Vector3(1.0F) + Dim AmountRotated As Vector3 = New Vector3(0.0F) + Dim ReadyAxis As Vector3 = New Vector3(0.0F) Public RemoveEntityAfter As Boolean = False Public Sub New(ByVal Entity As Entity, ByVal RemoveEntityAfter As Boolean, ByVal RotationSpeedVector As Vector3, ByVal EndRotation As Vector3, ByVal startDelay As Single, ByVal endDelay As Single) @@ -25,12 +27,15 @@ If DoXRotation = False Then DoRotation.X = 0.0F + ReadyAxis.X = 1.0F End If If DoYRotation = False Then DoRotation.Y = 0.0F + ReadyAxis.Y = 1.0F End If If DoZRotation = False Then DoRotation.Z = 0.0F + ReadyAxis.Z = 1.0F End If End Sub @@ -41,9 +46,8 @@ End Sub Public Overrides Sub DoActionActive() - If VectorReached() = False Then - - If DoRotation.X = 1.0F Then + If DoRotation.X = 1.0F Then + If AmountRotated.X < Math.Abs(EndRotation.X) Then If TargetEntity.Rotation.X > Me.EndRotation.X Then TargetEntity.Rotation.X += Me.RotationSpeedVector.X @@ -57,9 +61,13 @@ TargetEntity.Rotation.X = Me.EndRotation.X End If End If + AmountRotated.X += Math.Abs(Me.RotationSpeedVector.X) + Else + ReadyAxis.X = 1.0F End If - - If DoRotation.Y = 1.0F Then + End If + If DoRotation.Y = 1.0F Then + If AmountRotated.Y < Math.Abs(EndRotation.Y) Then If TargetEntity.Rotation.Y > Me.EndRotation.Y Then TargetEntity.Rotation.Y += Me.RotationSpeedVector.Y @@ -73,9 +81,15 @@ TargetEntity.Rotation.Y = Me.EndRotation.Y End If End If + AmountRotated.Y += Math.Abs(Me.RotationSpeedVector.Y) + Else + ReadyAxis.y = 1.0F End If + End If + + If DoRotation.Z = 1.0F Then + If AmountRotated.Z < Math.Abs(EndRotation.Z) Then - If DoRotation.Z = 1.0F Then If TargetEntity.Rotation.Z > Me.EndRotation.Z Then TargetEntity.Rotation.Z += Me.RotationSpeedVector.Z @@ -89,42 +103,37 @@ TargetEntity.Rotation.Z = Me.EndRotation.Z End If End If + AmountRotated.Z += Math.Abs(Me.RotationSpeedVector.Z) + Else + ReadyAxis.Z = 1.0F End If - Else + End If + + If ReadyAxis.X = 1.0F AndAlso ReadyAxis.Y = 1.0F AndAlso ReadyAxis.Z = 1.0F Then RotationReady() End If End Sub Private Sub RotationReady() + If Me.DoReturn = True And Me.hasReturned = False Then Me.hasReturned = True Me.EndRotation = Me.ReturnVector Me.RotationSpeedVector = New Vector3(Me.RotationSpeedVector.X * -1, Me.RotationSpeedVector.Y * -1, Me.RotationSpeedVector.Z * -1) + If DoRotation.X = 1.0F Then + ReadyAxis.X = 0.0F + End If + If DoRotation.Y = 1.0F Then + ReadyAxis.Y = 0.0F + End If + If DoRotation.Z = 1.0F Then + ReadyAxis.Z = 0.0F + End If Else Me.Ready = True End If End Sub - Private Function VectorReached() As Boolean - If DoRotation.X = 1.0F Then - If EndRotation.X <> TargetEntity.Rotation.X Then - Return False - End If - End If - If DoRotation.Y = 1.0F Then - If EndRotation.Y <> TargetEntity.Rotation.Y Then - Return False - End If - End If - If DoRotation.Z = 1.0F Then - If EndRotation.Z <> TargetEntity.Rotation.Z Then - Return False - End If - End If - - Return True - End Function - Public Overrides Sub DoRemoveEntity() If Me.RemoveEntityAfter = True Then TargetEntity.CanBeRemoved = True diff --git a/P3D/Battle/BattleAnimations/BattleAnimation3D.vb b/P3D/Battle/BattleAnimations/BattleAnimation3D.vb index 2a4264b12..33efabcd6 100644 --- a/P3D/Battle/BattleAnimations/BattleAnimation3D.vb +++ b/P3D/Battle/BattleAnimations/BattleAnimation3D.vb @@ -32,6 +32,7 @@ Private StartDelayFraction As Single Private EndDelayWhole As Single Private EndDelayFraction As Single + Private hasStartedEndDelay As Boolean = False Public Sub New(ByVal Position As Vector3, ByVal Texture As Texture2D, ByVal Scale As Vector3, ByVal startDelay As Single, ByVal endDelay As Single, Optional SpawnedEntity As Boolean = False) MyBase.New(Position.X, Position.Y, Position.Z, "BattleAnimation", {Texture}, {0, 0}, False, 0, Scale, BaseModel.BillModel, 0, "", New Vector3(1.0F)) @@ -48,16 +49,21 @@ End Sub Public Overrides Sub Update() + If Started = False Then Me.startDelay = Date.Now + New TimeSpan(0, 0, 0, CInt(StartDelayWhole), CInt(StartDelayFraction * 1000)) - Me.endDelay = Date.Now + New TimeSpan(0, 0, 0, CInt(EndDelayWhole), CInt(EndDelayFraction * 1000)) + hasStartedEndDelay = False Started = True End If If CanRemove = False Then If Ready = True Then + If hasStartedEndDelay = False Then + Me.endDelay = Date.Now + New TimeSpan(0, 0, 0, CInt(EndDelayWhole), CInt(EndDelayFraction * 1000)) + hasStartedEndDelay = True + End If If Date.Now >= endDelay Then - CanRemove = True DoRemoveEntity() + CanRemove = True End If Else If Date.Now >= startDelay Then