diff --git a/Content/Audio/jumpland_var1.flax b/Content/Audio/jumpland_var1.flax index 016a0dd..fe9100b 100644 Binary files a/Content/Audio/jumpland_var1.flax and b/Content/Audio/jumpland_var1.flax differ diff --git a/Content/Audio/jumpland_var2.flax b/Content/Audio/jumpland_var2.flax index f6ea8f0..fc426a3 100644 Binary files a/Content/Audio/jumpland_var2.flax and b/Content/Audio/jumpland_var2.flax differ diff --git a/Content/Audio/jumpland_var3.flax b/Content/Audio/jumpland_var3.flax index c02fc22..67a1ebd 100644 Binary files a/Content/Audio/jumpland_var3.flax and b/Content/Audio/jumpland_var3.flax differ diff --git a/Content/Common/PlayerPrefab.prefab b/Content/Common/PlayerPrefab.prefab index fccc07f..20f6671 100644 --- a/Content/Common/PlayerPrefab.prefab +++ b/Content/Common/PlayerPrefab.prefab @@ -56,6 +56,7 @@ "ParentID": "51c770f24232abbb112cc98b296820d8", "Name": "Camera", "StaticFlags": 0, + "FOV": 65.0, "Near": 1.0, "RenderLayersMask": 4294967291 }, @@ -68,112 +69,24 @@ "material": "c3ddff6e40ca5db834b2629771038d21" } }, - { - "ID": "1cf14d02487b7bd9f5c85b9ab437bfc7", - "TypeName": "FlaxEngine.AudioListener", - "ParentID": "eb46ab96465957dc67a052bd0e2ad1e5", - "Name": "AudioListener", - "StaticFlags": 0 - }, { "ID": "0e2e8a4f4623887ca2be699fe858beb2", "TypeName": "FlaxEngine.Camera", "ParentID": "51c770f24232abbb112cc98b296820d8", - "Name": "Camera2", + "Name": "ViewModelCamera", "StaticFlags": 0, "Layer": 2, + "FOV": 65.0, "Near": 1.0, "Far": 505.0, "RenderLayersMask": 4294967294 }, { - "ID": "b458fab04186b0cae4563ba49ac6a3f9", - "TypeName": "FlaxEngine.EmptyActor", + "ID": "262c688d49caaf66eb7e6a97f0d01206", + "TypeName": "FlaxEngine.AudioListener", "ParentID": "51c770f24232abbb112cc98b296820d8", - "Name": "WeaponHolder", - "Transform": { - "Orientation": { - "X": 0.0, - "Y": -1.0, - "Z": 0.0, - "W": -4.371138828673793e-8 - } - }, - "Layer": 2 - }, - { - "ID": "293ff021499bbcb5c4b263894f5d327b", - "TypeName": "FlaxEngine.StaticModel", - "ParentID": "b458fab04186b0cae4563ba49ac6a3f9", - "Name": "DummyWeapon", - "Transform": { - "Translation": { - "X": -10.751121520996094, - "Y": -15.242582321166993, - "Z": -17.880233764648439 - }, - "Orientation": { - "X": -2.9248639066281613e-8, - "Y": 0.7431446313858032, - "Z": -0.6691308617591858, - "W": -3.24838822507445e-8 - }, - "Scale": { - "X": 0.07999999821186066, - "Y": 0.431741327047348, - "Z": 0.07999999821186066 - } - }, - "StaticFlags": 0, - "Layer": 2, - "Model": "223aa9894e90973780ab508621517526", - "Buffer": { - "Entries": [ - { - "Material": "59d8bf5b4addd14c1e8f6089d1c3577c", - "ShadowsMode": 3, - "Visible": true, - "ReceiveDecals": true - } - ] - } - }, - { - "ID": "f00bd71c4e71c00fef2d70bd90cce128", - "TypeName": "FlaxEngine.StaticModel", - "ParentID": "b458fab04186b0cae4563ba49ac6a3f9", - "Name": "DummyWeapon 0", - "Transform": { - "Translation": { - "X": -10.764251708984375, - "Y": -13.419981002807618, - "Z": -33.95440673828125 - }, - "Orientation": { - "X": -2.9248639066281613e-8, - "Y": 0.7431446313858032, - "Z": -0.6691308617591858, - "W": -3.24838822507445e-8 - }, - "Scale": { - "X": 0.11999999731779099, - "Y": 0.11855093389749527, - "Z": 0.11999999731779099 - } - }, - "StaticFlags": 0, - "Layer": 2, - "Model": "223aa9894e90973780ab508621517526", - "Buffer": { - "Entries": [ - { - "Material": "ae5c8a4b4f723b60b8b31290a9dfb21a", - "ShadowsMode": 3, - "Visible": true, - "ReceiveDecals": true - } - ] - } + "Name": "AudioListener", + "StaticFlags": 0 }, { "ID": "a5850c1640208268c45f2892fe6b9e45", @@ -230,6 +143,102 @@ }, "StaticFlags": 0, "CollisionData": "593d92914c4bd54679ddec9e539bba80" + }, + { + "ID": "56eddcef4698702bd3cb0b8a1fb3396f", + "TypeName": "FlaxEngine.EmptyActor", + "ParentID": "a50f3639419a8306036ecfab7115e772", + "Name": "ViewModelHolder", + "Transform": { + "Translation": { + "X": 0.0, + "Y": 22.0, + "Z": 0.0 + } + }, + "Layer": 2 + }, + { + "ID": "195f796349961ef9a9d46a8657fc693b", + "TypeName": "Game.WeaponSway", + "ParentID": "56eddcef4698702bd3cb0b8a1fb3396f", + "V": { + "swaySpeed": 90.0 +} + }, + { + "ID": "111ba6ba4129558d16c0629bb31a55f9", + "TypeName": "FlaxEngine.StaticModel", + "ParentID": "56eddcef4698702bd3cb0b8a1fb3396f", + "Name": "DummyWeapon", + "Transform": { + "Translation": { + "X": 7.394217491149902, + "Y": -11.22248649597168, + "Z": -3.27701997756958 + }, + "Orientation": { + "X": 0.6691311001777649, + "Y": 0.0, + "Z": 0.0, + "W": 0.7431443929672241 + }, + "Scale": { + "X": 0.07999999821186066, + "Y": 0.431741327047348, + "Z": 0.07999999821186066 + } + }, + "StaticFlags": 0, + "Layer": 2, + "Model": "223aa9894e90973780ab508621517526", + "Buffer": { + "Entries": [ + { + "Material": "59d8bf5b4addd14c1e8f6089d1c3577c", + "ShadowsMode": 3, + "Visible": true, + "ReceiveDecals": true + } + ] + } + }, + { + "ID": "99a5bfe4459e3ac2c3f0198ede38a587", + "TypeName": "FlaxEngine.StaticModel", + "ParentID": "56eddcef4698702bd3cb0b8a1fb3396f", + "Name": "DummyWeapon 0", + "Transform": { + "Translation": { + "X": 7.35720682144165, + "Y": -9.197076797485352, + "Z": 15.981095314025879 + }, + "Orientation": { + "X": 0.6691311001777649, + "Y": 0.0, + "Z": 0.0, + "W": 0.7431443929672241 + }, + "Scale": { + "X": 0.09000000357627869, + "Y": 0.05855093151330948, + "Z": 0.09000000357627869 + } + }, + "StaticFlags": 0, + "Layer": 2, + "Model": "223aa9894e90973780ab508621517526", + "Buffer": { + "Entries": [ + { + "Material": "ae5c8a4b4f723b60b8b31290a9dfb21a", + "ShadowsMode": 3, + "Visible": true, + "ReceiveDecals": true + } + ] + } } ] } \ No newline at end of file diff --git a/Content/Scenes/AerowalkScene.scene b/Content/Scenes/AerowalkScene.scene index 794d0c5..e64cda0 100644 --- a/Content/Scenes/AerowalkScene.scene +++ b/Content/Scenes/AerowalkScene.scene @@ -76,7 +76,7 @@ }, "Control": "FlaxEngine.GUI.Label", "Data": { - "Text": "eFPS: 96\nuFPS: 96\nrFPS: 96\npFPS: 30", + "Text": "eFPS: 15 uTime: 176.6672213\nuFPS: 15 uTime: 0.00833330024033785\nrFPS: 15 rTime: 0\npFPS: 30 pTime: 0", "TextColor": { "R": 1.0, "G": 1.0, @@ -123,7 +123,7 @@ }, "Offsets": { "Left": 0.0, - "Right": 50.0, + "Right": 224.0, "Top": -97.0, "Bottom": 64.0 }, @@ -334,7 +334,7 @@ }, "AA": { "OverrideFlags": 1, - "Mode": 2 + "Mode": 0 }, "PostFxMaterials": {} } @@ -380,12 +380,6 @@ "camera": "711a0025492161a44f48afa6e591b6ab" } }, - { - "ID": "4bedd9724ad22177fbf75f9bf51cc27f", - "PrefabID": "82e58c9d462fba5a0df1a599417ff684", - "PrefabObjectID": "1cf14d02487b7bd9f5c85b9ab437bfc7", - "ParentID": "86dbba284fbe908c9e62b89493e9a83f" - }, { "ID": "711a0025492161a44f48afa6e591b6ab", "PrefabID": "82e58c9d462fba5a0df1a599417ff684", @@ -393,51 +387,11 @@ "ParentID": "f4ab880f47cab1ca423ce8b04f524ac2" }, { - "ID": "f3b9d1594b1f2fc5b793adb5f144ab46", + "ID": "4bedd9724ad22177fbf75f9bf51cc27f", "PrefabID": "82e58c9d462fba5a0df1a599417ff684", - "PrefabObjectID": "b458fab04186b0cae4563ba49ac6a3f9", + "PrefabObjectID": "262c688d49caaf66eb7e6a97f0d01206", "ParentID": "f4ab880f47cab1ca423ce8b04f524ac2" }, - { - "ID": "d267a9954013a72391bd3a921d214639", - "PrefabID": "82e58c9d462fba5a0df1a599417ff684", - "PrefabObjectID": "293ff021499bbcb5c4b263894f5d327b", - "ParentID": "f3b9d1594b1f2fc5b793adb5f144ab46", - "Transform": { - "Translation": { - "X": -10.751110076904297, - "Y": -15.242582321166993, - "Z": -17.880233764648439 - }, - "Orientation": { - "X": -2.9248639066281613e-8, - "Y": 0.7431446313858032, - "Z": -0.6691308617591858, - "W": -3.24838822507445e-8 - }, - "Scale": { - "X": 0.07999999821186066, - "Y": 0.431741327047348, - "Z": 0.07999999821186066 - } - }, - "Buffer": { - "Entries": [ - {} - ] - } - }, - { - "ID": "0bf71acc46ee83ac2cfffbb9269bcd11", - "PrefabID": "82e58c9d462fba5a0df1a599417ff684", - "PrefabObjectID": "f00bd71c4e71c00fef2d70bd90cce128", - "ParentID": "f3b9d1594b1f2fc5b793adb5f144ab46", - "Buffer": { - "Entries": [ - {} - ] - } - }, { "ID": "b8dde5a34570002b6b5666a89d6a70cb", "PrefabID": "82e58c9d462fba5a0df1a599417ff684", @@ -456,6 +410,41 @@ "PrefabObjectID": "3932111d4c6f925a7b4a2e912307c82a", "ParentID": "59cc65774b36b4a58a274fb7b4e9d490" }, + { + "ID": "f3b9d1594b1f2fc5b793adb5f144ab46", + "PrefabID": "82e58c9d462fba5a0df1a599417ff684", + "PrefabObjectID": "56eddcef4698702bd3cb0b8a1fb3396f", + "ParentID": "59cc65774b36b4a58a274fb7b4e9d490" + }, + { + "ID": "8ef08cf4468a34df2e97d8a971d5a2dd", + "PrefabID": "82e58c9d462fba5a0df1a599417ff684", + "PrefabObjectID": "195f796349961ef9a9d46a8657fc693b", + "ParentID": "f3b9d1594b1f2fc5b793adb5f144ab46", + "V": {} + }, + { + "ID": "d267a9954013a72391bd3a921d214639", + "PrefabID": "82e58c9d462fba5a0df1a599417ff684", + "PrefabObjectID": "111ba6ba4129558d16c0629bb31a55f9", + "ParentID": "f3b9d1594b1f2fc5b793adb5f144ab46", + "Buffer": { + "Entries": [ + {} + ] + } + }, + { + "ID": "0bf71acc46ee83ac2cfffbb9269bcd11", + "PrefabID": "82e58c9d462fba5a0df1a599417ff684", + "PrefabObjectID": "99a5bfe4459e3ac2c3f0198ede38a587", + "ParentID": "f3b9d1594b1f2fc5b793adb5f144ab46", + "Buffer": { + "Entries": [ + {} + ] + } + }, { "ID": "9b9be0a542cc06e3172f4ea660188187", "TypeName": "FlaxEngine.PointLight", diff --git a/Content/Settings/EngineSettings/BuildSettings.json b/Content/Settings/EngineSettings/BuildSettings.json index 37dc02f..f0044aa 100644 --- a/Content/Settings/EngineSettings/BuildSettings.json +++ b/Content/Settings/EngineSettings/BuildSettings.json @@ -1,7 +1,7 @@ { "ID": "af2e52554f7faed7b4937181dd22d166", "TypeName": "FlaxEditor.Content.Settings.BuildSettings", - "EngineBuild": 6225, + "EngineBuild": 6331, "Data": { "MaxAssetsPerPackage": 4096, "MaxPackageSizeMB": 1024, @@ -11,30 +11,32 @@ "AdditionalAssets": [], "AdditionalAssetFolders": [ "Content/Materials", - "Content/Textures" + "Content/Textures", + "Content/Audio" ], "ShadersNoOptimize": false, "ShadersGenerateDebugData": false, "Presets": [ { - "Name": "Development", + "Name": "Preset 3", "Targets": [ { - "Name": "Win64", - "Output": "Output\\WindowsDevelopment", - "Platform": 2, - "Mode": 1 - } - ] - }, - { - "Name": "Release", - "Targets": [ - { - "Name": "Win64", + "Name": "Win64 Release", "Output": "Output\\WindowsRelease", "Platform": 2, - "Mode": 2 + "Mode": 2, + "CustomDefines": null, + "PreBuildAction": null, + "PostBuildAction": null + }, + { + "Name": "Win64 Development", + "Output": "Output\\WindowsDevelopment", + "Platform": 2, + "Mode": 1, + "CustomDefines": null, + "PreBuildAction": null, + "PostBuildAction": null } ] } diff --git a/Content/Settings/EngineSettings/PhysicsSettings.json b/Content/Settings/EngineSettings/PhysicsSettings.json index a319f8c..28650d9 100644 --- a/Content/Settings/EngineSettings/PhysicsSettings.json +++ b/Content/Settings/EngineSettings/PhysicsSettings.json @@ -17,8 +17,8 @@ "EnableAdaptiveForce": false, "MaxDeltaTime": 0.1, "EnableSubstepping": false, - "SubstepDeltaTime": 0.001, - "MaxSubsteps": 60, + "SubstepDeltaTime": 1E-05, + "MaxSubsteps": 600, "SupportCookingAtRuntime": true, "LayerMasks": [ 4294967295, diff --git a/Content/Settings/EngineSettings/TimeSettings.json b/Content/Settings/EngineSettings/TimeSettings.json index 0081d24..0b44d8b 100644 --- a/Content/Settings/EngineSettings/TimeSettings.json +++ b/Content/Settings/EngineSettings/TimeSettings.json @@ -6,7 +6,7 @@ "UpdateMode": 1, "UpdateFPS": 120.0, "PhysicsFPS": 120.0, - "DrawFPS": 0.0, + "DrawFPS": 120.0, "TimeScale": 1.0, "MaxUpdateDeltaTime": 0.1 } diff --git a/Source/Game/AudioManager.cs b/Source/Game/AudioManager.cs index f0ab961..cfb0c93 100644 --- a/Source/Game/AudioManager.cs +++ b/Source/Game/AudioManager.cs @@ -82,20 +82,18 @@ namespace Game { // Check if this audio has multiple variations List audioClips = new List(); - int index = 1; - do + for (int i = 1; i<50; i++) { - // TODO: make this more efficient, maybe get a list of assets and filter by name - audioClip = Content.Load(Path.Combine(audioBasePath, soundName + "_var" + index + ".flax")); - if (audioClip != null) - audioClips.Add(audioClip); - index++; - } while (audioClip != null); + // TODO: make this more efficient, maybe get a list of assets and filter by name? + AudioClip audioClipVariation = Content.Load(Path.Combine(audioBasePath, soundName + "_var" + i + ".flax")); + if (audioClipVariation == null) + break; + + audioClips.Add(audioClipVariation); + } if (audioClips.Count > 0) - { audio.AudioClips = audioClips.ToArray(); - } else Console.PrintError("AudioClip '" + soundName + "' not found"); } diff --git a/Source/Game/Cabrito/FpsScript.cs b/Source/Game/Cabrito/FpsScript.cs index 7fa3de0..9e2f684 100644 --- a/Source/Game/Cabrito/FpsScript.cs +++ b/Source/Game/Cabrito/FpsScript.cs @@ -21,16 +21,21 @@ namespace Cabrito double updateTimeAvg = 0.0; ulong updateTimeCount; const double updateInterval = 0.25; + double updateAccumTime = 0.0; Stopwatch sw2; double drawTimeAvg = 0.0; ulong drawTimeCount; const double drawInterval = 0.25; + double drawAccumTime = 0.0; Stopwatch sw3; double physicsTimeAvg = 0.0; ulong physicsTimeCount; const double physicsInterval = 0.25; + double physicsAccumTime = 0.0; + + Stopwatch sw0; string currentRenderer = "Unknown"; @@ -43,10 +48,12 @@ namespace Cabrito label = (Label) control.Control; sw = Stopwatch.StartNew(); + sw2 = Stopwatch.StartNew(); + sw3 = Stopwatch.StartNew(); + sw0 = Stopwatch.StartNew(); currentRenderer = GPUDevice.Instance.RendererType.ToString(); - sw2 = Stopwatch.StartNew(); if (t == null) { //Destroy(t); @@ -54,8 +61,6 @@ namespace Cabrito t.Render += OnDraw; } - sw3 = Stopwatch.StartNew(); - var settings = FlaxEditor.Content.Settings.GameSettings.Load(); timeSettings = settings.Time.CreateInstance(); } @@ -70,6 +75,7 @@ namespace Cabrito public override void OnUpdate() { + updateAccumTime += Time.DeltaTime; updateTimeCount++; double elapsed = sw.Elapsed.TotalSeconds; if (elapsed >= updateInterval) @@ -85,9 +91,13 @@ namespace Cabrito StringBuilder sb = new StringBuilder(); sb.Append("eFPS: " + Engine.FramesPerSecond); - sb.Append("\nuFPS: " + ((int) Math.Round(1.0f / updateTimeAvg)).ToString()); - sb.Append("\nrFPS: " + ((int) Math.Round(1.0f / drawTimeAvg)).ToString()); - sb.Append("\npFPS: " + ((int) Math.Round(1.0f / physicsTimeAvg)).ToString()); + sb.Append(" uTime: " + sw0.Elapsed.TotalSeconds); + sb.Append("\nuFPS: " + ((int) Math.Round(1.0f / updateTimeAvg))); + sb.Append(" uTime: " + updateAccumTime); + sb.Append("\nrFPS: " + ((int) Math.Round(1.0f / drawTimeAvg))); + sb.Append(" rTime: " + drawAccumTime); + sb.Append("\npFPS: " + ((int) Math.Round(1.0f / physicsTimeAvg))); + sb.Append(" pTime: " + physicsAccumTime); //sb.Append("\nCon: " + conTime.ToString() + "ms"); //sb.Append("\nGC memory: " + (GC.GetTotalMemory(false) / 1000000.0f).ToString() + "MB"); //sb.Append("\nUpdate profiler: " + updateProfTime.ToString() + "ms"); @@ -148,6 +158,7 @@ namespace Cabrito public override void OnFixedUpdate() { + physicsAccumTime += Time.DeltaTime; physicsTimeCount++; double elapsed = sw3.Elapsed.TotalSeconds; if (elapsed >= physicsInterval) @@ -160,6 +171,7 @@ namespace Cabrito void OnDraw(RenderTask tt, GPUContext context) { + drawAccumTime += Time.DeltaTime; drawTimeCount++; double elapsed = sw2.Elapsed.TotalSeconds; if (elapsed >= drawInterval) diff --git a/Source/Game/CameraRender.cs b/Source/Game/CameraRender.cs index 41aab7c..65c848d 100644 --- a/Source/Game/CameraRender.cs +++ b/Source/Game/CameraRender.cs @@ -1,4 +1,5 @@ -using FlaxEngine; +using FlaxEditor.Content.Settings; +using FlaxEngine; using Console = Cabrito.Console; namespace Game @@ -89,6 +90,16 @@ namespace Game public override void OnUpdate() { +#if FLAX_EDITOR + if (Input.GetKeyDown(KeyboardKeys.F7)) + { + var physicsSettings = GameSettings.Load(); + physicsSettings.EnableSubstepping = !physicsSettings.EnableSubstepping; + GameSettings.Save(physicsSettings); + //GameSettings.Apply(); + } +#endif + if (!camera.IsActive) return; if (texture == null) diff --git a/Source/Game/PlayerMovement.cs b/Source/Game/PlayerMovement.cs index e17d134..7a2950e 100644 --- a/Source/Game/PlayerMovement.cs +++ b/Source/Game/PlayerMovement.cs @@ -30,6 +30,8 @@ namespace Game { [Limit(0, 9000), Tooltip("Base Movement speed")] public float MoveSpeed { get; set; } = 320; + + private static Vector3 Gravity { get; set; } = new Vector3(0, -800.0f, 0f); private float viewPitch; private float viewYaw; @@ -54,7 +56,7 @@ namespace Game base.OnAwake(); bool record = false; - //record = true; + record = true; if (record) { @@ -62,8 +64,8 @@ namespace Game } else { - input = new PlayerInputLocal(); - //input = new PlayerInputDemo(@"C:\dev\GoakeFlax\testdemo.gdem"); //playback + //input = new PlayerInputLocal(); + input = new PlayerInputDemo(@"C:\dev\GoakeFlax\testdemo.gdem"); //playback //input = new PlayerInputDemo(@"C:\dev\GoakeFlax\testdemo_desync.gdem"); //playback } @@ -184,6 +186,10 @@ namespace Game if (input is PlayerInputDemo) input.OnUpdate(); + float deltadif = Time.DeltaTime - (1.0f / Time.PhysicsFPS); + if (Math.Abs(deltadif) > 0.0001f) + Console.Print("drift: " + deltadif); + input.OnFixedUpdate(); PlayerInputState inputState = input.GetCurrentInputState(); @@ -525,7 +531,7 @@ namespace Game // hit something, try to step up if (onGround) { - Vector3 stepDelta = -Physics.Gravity.Normalized * stepSize; + Vector3 stepDelta = -Gravity.Normalized * stepSize; Vector3 slidePosition = position; Vector3 slideVelocity = velocity; @@ -544,11 +550,11 @@ namespace Game // step down Vector3 stepDown = position - stepDelta; TraceInfo traceDown = TracePlayer(actor, position, stepDown); - if (traceDown.fraction < 1f && -Vector3.Dot(Physics.Gravity.Normalized, traceDown.hitNormal) < slopeNormal) + if (traceDown.fraction < 1f && -Vector3.Dot(Gravity.Normalized, traceDown.hitNormal) < slopeNormal) { // can't step down, slide move like normally Console.Print("no stepping 1, frac: " + traceDown.fraction + ", dot: " + - (-Vector3.Dot(Physics.Gravity.Normalized, traceDown.hitNormal)) + + (-Vector3.Dot(Gravity.Normalized, traceDown.hitNormal)) + ", norm: " + traceDown.hitNormal); position = slidePosition; velocity = slideVelocity; @@ -562,8 +568,8 @@ namespace Game position.Y += collisionMargin; // ?? - var d1 = -Vector3.Dot(Physics.Gravity.Normalized, position); - var d2 = -Vector3.Dot(Physics.Gravity.Normalized, originalPosition); + var d1 = -Vector3.Dot(Gravity.Normalized, position); + var d2 = -Vector3.Dot(Gravity.Normalized, originalPosition); if (d1 < d2) { //Console.Print("no stepping 2, " + d1 + " < " + d2); @@ -818,13 +824,13 @@ namespace Game // categorize position onGround = true; - Vector3 groundDelta = Physics.Gravity.Normalized;//Physics.Gravity.Normalized * (collisionMargin * 2); + Vector3 groundDelta = Gravity.Normalized;//Gravity.Normalized * (collisionMargin * 2); //if (velocity.Y < 0f) - // groundDelta = Physics.Gravity.Normalized * velocity.Y * Time.DeltaTime; + // groundDelta = Gravity.Normalized * velocity.Y * Time.DeltaTime; TraceInfo traceGround = TracePlayer(Actor, position, position + groundDelta); if (!traceGround.startSolid && traceGround.fraction < 1f && - -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < slopeNormal) + -Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal) { //Console.Print("slope?"); // slope @@ -845,7 +851,7 @@ namespace Game } if (!traceGround.startSolid && (traceGround.fraction >= 1f || - -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < slopeNormal)) + -Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)) { // falling or sliding down a slope onGround = false; @@ -873,7 +879,7 @@ namespace Game { // reset velocity from gravity - if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 && + if (-Vector3.Dot(Gravity.Normalized, velocity) < 0 && Vector3.Dot(velocity, traceGround.hitNormal) < -0.1) { velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal); @@ -949,7 +955,7 @@ namespace Game // PM_Aircontrol(wishdir, wishspeedAirControl); // apply gravity - velocity += Physics.Gravity * Time.DeltaTime; + velocity += Gravity * Time.DeltaTime; //Console.Print(Time.DeltaTime.ToString()); } diff --git a/Source/Game/WeaponSway.cs b/Source/Game/WeaponSway.cs new file mode 100644 index 0000000..0f964e9 --- /dev/null +++ b/Source/Game/WeaponSway.cs @@ -0,0 +1,205 @@ +using System; +using System.Collections.Generic; +using FlaxEngine; +using Console = Cabrito.Console; + +namespace Game +{ + public class WeaponSway : Script + { + private Actor rootActor; + private Actor cameraHolder; + public override void OnStart() + { + rootActor = Actor.Parent.GetChild("RootActor"); + cameraHolder = rootActor.GetChild("CameraHolder"); + Actor.LocalOrientation = GetRotation(); + } + + + float easeInSine( float t ) { + return Mathf.Sin( 1.5707963f * t ); + } + + float easeOutSine( float t ) { + return 1 + Mathf.Sin( 1.5707963f * (--t) ); + } + + float easeInOutSine( float t ) { + return 0.5f * (1 + Mathf.Sin( 3.1415926f * (t - 0.5f) ) ); + } + + float easeInQuad( float t ) { + return t * t; + } + + float easeOutQuad( float t ) { + return t * (2 - t); + } + + float easeInOutQuad( float t ) { + return t < 0.5 ? 2 * t * t : t * (4 - 2 * t) - 1; + } + + float easeInCubic( float t ) { + return t * t * t; + } + + float easeOutCubic( float t ) { + return 1 + (--t) * t * t; + } + + float easeInOutCubic( float t ) { + return t < 0.5 ? 4 * t * t * t : 1 + (--t) * (2 * (--t)) * (2 * t); + } + + float easeInQuart( float t ) { + t *= t; + return t * t; + } + + float easeOutQuart( float t ) { + t = (--t) * t; + return 1 - t * t; + } + + float easeInOutQuart( float t ) { + if( t < 0.5 ) { + t *= t; + return 8 * t * t; + } else { + t = (--t) * t; + return 1 - 8 * t * t; + } + } + + float easeInQuint( float t ) { + float t2 = t * t; + return t * t2 * t2; + } + + float easeOutQuint( float t ) { + float t2 = (--t) * t; + return 1 + t * t2 * t2; + } + + float easeInOutQuint( float t ) { + float t2; + if( t < 0.5 ) { + t2 = t * t; + return 16 * t * t2 * t2; + } else { + t2 = (--t) * t; + return 1 + 16 * t * t2 * t2; + } + } + + float easeInExpo( float t ) { + return (Mathf.Pow( 2, 8 * t ) - 1) / 255; + } + + float easeOutExpo( float t ) { + return 1 - Mathf.Pow( 2, -8 * t ); + } + + float easeInOutExpo( float t ) { + if( t < 0.5 ) { + return (Mathf.Pow( 2, 16 * t ) - 1) / 510; + } else { + return 1 - 0.5f * Mathf.Pow( 2, -16 * (t - 0.5f) ); + } + } + + float easeInCirc( float t ) { + return 1 - Mathf.Sqrt( 1 - t ); + } + + float easeOutCirc( float t ) { + return Mathf.Sqrt( t ); + } + + float easeInOutCirc( float t ) { + if( t < 0.5 ) { + return (1 - Mathf.Sqrt( 1 - 2 * t )) * 0.5f; + } else { + return (1 + Mathf.Sqrt( 2 * t - 1 )) * 0.5f; + } + } + + float easeInBack( float t ) { + return t * t * (2.70158f * t - 1.70158f); + } + + float easeOutBack( float t ) { + return 1 + (--t) * t * (2.70158f * t + 1.70158f); + } + + float easeInOutBack( float t ) { + if( t < 0.5 ) { + return t * t * (7 * t - 2.5f) * 2; + } else { + return 1 + (--t) * t * 2 * (7 * t + 2.5f); + } + } + + float easeInElastic( float t ) { + float t2 = t * t; + return t2 * t2 * Mathf.Sin( t * (float)Math.PI * 4.5f ); + } + + float easeOutElastic( float t ) { + float t2 = (t - 1) * (t - 1); + return 1 - t2 * t2 * Mathf.Cos( t * (float)Math.PI * 4.5f ); + } + + float easeInOutElastic( float t ) { + float t2; + if( t < 0.45 ) { + t2 = t * t; + return 8 * t2 * t2 * Mathf.Sin( t * (float)Math.PI * 9 ); + } else if( t < 0.55 ) { + return 0.5f + 0.75f * Mathf.Sin( t * (float)Math.PI * 4 ); + } else { + t2 = (t - 1) * (t - 1); + return 1 - 8 * t2 * t2 * Mathf.Sin( t * (float)Math.PI * 9 ); + } + } + + float easeInBounce( float t ) { + return Mathf.Pow( 2, 6 * (t - 1) ) * Mathf.Abs( Mathf.Sin( t * (float)Math.PI * 3.5f ) ); + } + + float easeOutBounce( float t ) { + return 1 - Mathf.Pow( 2, -6 * t ) * Mathf.Abs( Mathf.Cos( t * (float)Math.PI * 3.5f ) ); + } + + float easeInOutBounce( float t ) { + if( t < 0.5 ) { + return 8 * Mathf.Pow( 2, 8 * (t - 1) ) * Mathf.Abs( Mathf.Sin( t * (float)Math.PI * 7 ) ); + } else { + return 1 - 8 * Mathf.Pow( 2, -8 * t ) * Mathf.Abs( Mathf.Sin( t * (float)Math.PI * 7 ) ); + } + } + + private Quaternion targetRotation; + private Quaternion oldRotation; + private Quaternion accumRotation; + + public float swaySpeed = 15f; + + private Quaternion GetRotation() + { + Quaternion pitch = cameraHolder.LocalOrientation; + Quaternion yawRoll = rootActor.LocalOrientation; + return yawRoll * pitch; + } + + public override void OnLateUpdate() + { + //easeInQuad + + Quaternion rotation = GetRotation(); + Actor.LocalOrientation = Quaternion.Lerp(Actor.LocalOrientation, rotation, Math.Min(1.0f, easeInCubic(swaySpeed * Time.DeltaTime))); + } + } +}