big performance improvement
This commit is contained in:
@@ -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>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
|
7
gd-mono-thirdpersoncontroller.csproj.old
Normal file
7
gd-mono-thirdpersoncontroller.csproj.old
Normal 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>
|
@@ -29,6 +29,10 @@ window/stretch/aspect="expand"
|
||||
|
||||
project/assembly_name="gd-mono-thirdpersoncontroller"
|
||||
|
||||
[editor]
|
||||
|
||||
export/convert_text_resources_to_binary=true
|
||||
|
||||
[input]
|
||||
|
||||
move_left={
|
||||
@@ -75,8 +79,5 @@ uncapture_mouse={
|
||||
|
||||
[rendering]
|
||||
|
||||
lights_and_shadows/directional_shadow/size=6144
|
||||
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=5
|
||||
anti_aliasing/quality/msaa_3d=2
|
||||
anti_aliasing/quality/screen_space_aa=1
|
||||
renderer/rendering_method="mobile"
|
||||
occlusion_culling/use_occlusion_culling=true
|
||||
|
@@ -2,18 +2,28 @@ using Godot;
|
||||
|
||||
public partial class player : CharacterBody3D
|
||||
{
|
||||
public Vector3 direction;
|
||||
[Export] float speed = 5.0f;
|
||||
[Export] float jumpVelocity = 5f;
|
||||
[Export] float gravity = 14f;
|
||||
[Export(PropertyHint.Range, "0.1,1.0")] float mouseSensitivity = 0.3f;
|
||||
[Export(PropertyHint.Range, "-90,0,1")] float minMousePitch = -50f;
|
||||
[Export(PropertyHint.Range, "0,90,1")] float maxMousePitch = 50f;
|
||||
[Export(PropertyHint.Range, "0,90,1")] float maxMousePitch = 50f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
//uncapturing the mouse disables player movement but still simulates gravity
|
||||
if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
if (Input.IsMouseButtonPressed(MouseButton.Left)) Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
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)
|
||||
{
|
||||
@@ -26,15 +36,11 @@ public partial class player : CharacterBody3D
|
||||
velocity.y = jumpVelocity;
|
||||
|
||||
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)
|
||||
{
|
||||
velocity.x = direction.x * 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
|
||||
{
|
||||
@@ -43,7 +49,7 @@ public partial class player : CharacterBody3D
|
||||
}
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured)
|
||||
@@ -51,8 +57,8 @@ public partial class player : CharacterBody3D
|
||||
Vector3 camRot = GetNode<Marker3D>("camera_center").RotationDegrees;
|
||||
camRot.y -= mouseMotion.Relative.x * mouseSensitivity;
|
||||
camRot.x -= mouseMotion.Relative.y * mouseSensitivity;
|
||||
camRot.x = Mathf.Clamp(camRot.x, minMousePitch, maxMousePitch); //prevents camera from going endlessly around the player
|
||||
GetNode<Marker3D>("camera_center").RotationDegrees = camRot;
|
||||
camRot.x = Mathf.Clamp(camRot.x, minMousePitch, maxMousePitch); //prevents camera from going endlessly around the player
|
||||
GetNode<Marker3D>("camera_center").RotationDegrees = camRot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,25 +3,13 @@ using System;
|
||||
|
||||
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 (DisplayServer.WindowGetMode() == DisplayServer.WindowMode.Fullscreen)
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
|
||||
else DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
|
||||
}
|
||||
}
|
||||
if (Input.IsActionJustPressed("fullscreen"))
|
||||
{
|
||||
if (DisplayServer.WindowGetMode() == DisplayServer.WindowMode.Fullscreen)
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
|
||||
else DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user