Here is the code where the problem is:
Code: Select all
Public Class Universe
Inherits NovaUniverse
Public IOManager As New IOStructManager
Public TurnAcceleration As Single = 0.001
Public TurnSpeed As Single = 0.01
Public ShipAcceleration As Single = 0.05
Dim ship As NovaRigidBodyBox
Public Sub New()
MyBase.New(1000, 1)
IOManager.Types.Add(New KeyStructCreator)
Worlds.Add(New NovaWorld(Me))
'LoadStill(0, "Dodgefight.nova")
'Generate asteroids
For x = -100 To 100 Step 60
For y = -100 To 100 Step 60
For z = -100 To 100 Step 60
AddSphere(0, New Vector3(x + (Rnd() * 8 - 4), y + (Rnd() * 8 - 4), z + (Rnd() * 8 - 4)), 10 + (Rnd() * 16 - 8), 0, "asteroid")
Next
Next
Next
ship = AddBox(0, New Vector3(0, 0, 0), New Vector3(1, 0.5, 2), 0.01, "asteroid")
ship.Node = -2
Worlds(0).World.Gravity = New Vector3
AddLight(0, New Vector3(0, 0, 0), New Colorf(1, 1, 1))
End Sub
Private Sub Universe_ReceivedMessage(ByVal bytes() As Byte) Handles Me.ReceivedMessage
Dim structs = IOManager.ExtractStructs(bytes)
Dim w = Worlds(0)
If ship.Body.ActivationState = ActivationState.IslandSleeping Then ship.Body.Activate()
Dim rotation = QuaternionToEuler(ship.Body.Orientation)
Dim mat As New Core.Matrix
mat.Rotation = Vector3ToVector3Df(rotation)
For Each s As KeyStruct In structs
If s.Key = 0 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(-s.Time * TurnAcceleration, 0, 0))))
ElseIf s.Key = 1 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(s.Time * TurnAcceleration, 0, 0))))
ElseIf s.Key = 2 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(0, -s.Time * TurnAcceleration, 0))))
ElseIf s.Key = 3 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(0, s.Time * TurnAcceleration, 0))))
ElseIf s.Key = 4 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(0, 0, -s.Time * TurnAcceleration))))
ElseIf s.Key = 5 Then
ship.Body.ApplyTorque(Vector3DfToVector3(mat.RotateVector(New Vector3Df(0, 0, s.Time * TurnAcceleration))))
End If
Next
End Sub
Public Overrides Sub Update()
Dim v = ship.Body.AngularVelocity
If v.X > TurnSpeed Then v.X = TurnSpeed
If v.Y > TurnSpeed Then v.Y = TurnSpeed
If v.Z > TurnSpeed Then v.Z = TurnSpeed
If -v.X > TurnSpeed Then v.X = -TurnSpeed
If -v.Y > TurnSpeed Then v.Y = -TurnSpeed
If -v.Z > TurnSpeed Then v.Z = -TurnSpeed
ship.Body.AngularVelocity = v
If My.Computer.Clock.TickCount > LastUpdateTime + 30 Then '30 ms, approx 30 fps
Dim m As New Core.Matrix 'BulletSharp.Matrix.RotationQuaternion(ship.Orientation)
Dim r = Vector3ToVector3Df(QuaternionToEuler(ship.Orientation))
'r = New Vector3Df(r.X, r.Y, r.z)
m.Rotation = r
Dim f As New Vector3Df(0, 0, -ShipAcceleration)
m.TransformVector(f)
ship.Body.ApplyCentralForce(Vector3DfToVector3(f))
End If
MyBase.Update()
End Sub