big performance improvement

This commit is contained in:
2023-01-24 13:41:25 +01:00
parent 983dbf978f
commit 17b2fd0817
5 changed files with 38 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.0.0-beta.10"> <Project Sdk="Godot.NET.Sdk/4.0.0-beta.13">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading> <EnableDynamicLoading>true</EnableDynamicLoading>

View File

@@ -0,0 +1,7 @@
<Project Sdk="Godot.NET.Sdk/4.0.0-beta.10">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>gd-mono-thirdpersoncontroller</RootNamespace>
</PropertyGroup>
</Project>

View File

@@ -29,6 +29,10 @@ window/stretch/aspect="expand"
project/assembly_name="gd-mono-thirdpersoncontroller" project/assembly_name="gd-mono-thirdpersoncontroller"
[editor]
export/convert_text_resources_to_binary=true
[input] [input]
move_left={ move_left={
@@ -75,8 +79,5 @@ uncapture_mouse={
[rendering] [rendering]
lights_and_shadows/directional_shadow/size=6144 renderer/rendering_method="mobile"
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=5
anti_aliasing/quality/msaa_3d=2
anti_aliasing/quality/screen_space_aa=1
occlusion_culling/use_occlusion_culling=true occlusion_culling/use_occlusion_culling=true

View File

@@ -2,6 +2,7 @@ using Godot;
public partial class player : CharacterBody3D public partial class player : CharacterBody3D
{ {
public Vector3 direction;
[Export] float speed = 5.0f; [Export] float speed = 5.0f;
[Export] float jumpVelocity = 5f; [Export] float jumpVelocity = 5f;
[Export] float gravity = 14f; [Export] float gravity = 14f;
@@ -14,6 +15,15 @@ public partial class player : CharacterBody3D
//uncapturing the mouse disables player movement but still simulates gravity //uncapturing the mouse disables player movement but still simulates gravity
if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible; if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible;
if (Input.IsMouseButtonPressed(MouseButton.Left)) Input.MouseMode = Input.MouseModeEnum.Captured; if (Input.IsMouseButtonPressed(MouseButton.Left)) Input.MouseMode = Input.MouseModeEnum.Captured;
/**body rotation is in regular process because it lags in physicsprocess and is more a animation anyway
maybe rotate extra collisions separately for invisible lag that may occur**/
if (direction != Vector3.Zero)
{
Vector3 bodyRotation = GetNode<MeshInstance3D>("collision/body").Rotation;
bodyRotation.y = Mathf.LerpAngle(bodyRotation.y,Mathf.Atan2(-direction.x, -direction.z), (float)delta * speed);
GetNode<MeshInstance3D>("collision/body").Rotation = bodyRotation;
}
} }
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
{ {
@@ -26,15 +36,11 @@ public partial class player : CharacterBody3D
velocity.y = jumpVelocity; velocity.y = jumpVelocity;
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward"); Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
Vector3 direction = new Vector3(inputDir.x, 0, inputDir.y).Rotated(Vector3.Up, GetNode<Marker3D>("camera_center").Rotation.y).Normalized(); //rotates the input direction with camera rotation direction = new Vector3(inputDir.x, 0, inputDir.y).Rotated(Vector3.Up, GetNode<Marker3D>("camera_center").Rotation.y).Normalized(); //rotates the input direction with camera rotation
if (direction != Vector3.Zero) if (direction != Vector3.Zero)
{ {
velocity.x = direction.x * speed; velocity.x = direction.x * speed;
velocity.z = direction.z * speed; velocity.z = direction.z * speed;
//Rotating the body mesh to movement
Vector3 bodyRotation = GetNode<MeshInstance3D>("collision/body").Rotation;
bodyRotation.y = Mathf.LerpAngle(bodyRotation.y,Mathf.Atan2(-direction.x, -direction.z), (float)delta * speed);
GetNode<MeshInstance3D>("collision/body").Rotation = bodyRotation;
} }
else else
{ {

View File

@@ -3,18 +3,6 @@ using System;
public partial class window : Node public partial class window : Node
{ {
public override async void _Ready()
{
/* VSync should be used because needing to change the PhysicsTicksPerSecond in _Process takes CPU ussage
* You could also just set max FPS and delte this fix
*/
await ToSignal(GetTree().CreateTimer(1.5f), "timeout");//waits until the game has loaded some time
if (Engine.PhysicsTicksPerSecond != (int)Engine.GetFramesPerSecond())
{
Engine.PhysicsTicksPerSecond = (int)Engine.GetFramesPerSecond(); //PhysicsTicksPerSecond have to be the same value like current FPS or the movement will lagg
GD.Print("Set PhysicsTicksPerSecond to: " + Engine.PhysicsTicksPerSecond);
}
}
public override void _Process(double delta) public override void _Process(double delta)
{ {
if (Input.IsActionJustPressed("fullscreen")) if (Input.IsActionJustPressed("fullscreen"))