Fixed rotate BattleAnimation & enddelay...

EndDelay for BattleAnimations is now correctly calculated
Rotate BattleAnimation now actually ends when it's done rotating
This commit is contained in:
JappaWakka 2023-06-20 15:55:47 +02:00
parent f93fc668c6
commit 592420abac
2 changed files with 44 additions and 29 deletions

View File

@ -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 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
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 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
End If
AmountRotated.Z += Math.Abs(Me.RotationSpeedVector.Z)
Else
ReadyAxis.Z = 1.0F
End If
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

View File

@ -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