Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b76342b8e6 | ||
|
72434b2480 | ||
|
8dbf6de4ea | ||
|
ce8f172d41 | ||
|
b398d66fba | ||
|
8a87fb2ac0 | ||
|
3d305f4188 | ||
ab3193c1f9 | |||
849abfdaf8 | |||
|
dd2ff50353 | ||
|
bc8a98ed3a |
@@ -1,7 +1,9 @@
|
|||||||
<Project Sdk="Godot.NET.Sdk/4.0.0-beta.16">
|
<Project Sdk="Godot.NET.Sdk/4.2.1">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
|
||||||
|
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
<RootNamespace>gd-mono-thirdpersoncontroller</RootNamespace>
|
<RootNamespace>gdmonothirdpersoncontroller</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@@ -1,6 +1,6 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2012
|
# Visual Studio 2012
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gd-mono-thirdpersoncontroller", "gd-mono-thirdpersoncontroller.csproj", "{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gd-mono-thirdpersoncontroller", "gd-mono-thirdpersoncontroller.csproj", "{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -9,11 +9,11 @@ Global
|
|||||||
ExportRelease|Any CPU = ExportRelease|Any CPU
|
ExportRelease|Any CPU = ExportRelease|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
|
||||||
{C0DA1341-EAB0-4F7B-BEA9-60129C156BFE}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
|
{AC7B5940-D2F5-4F43-AF3D-D23E4111E15D}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.cte
|
|||||||
[params]
|
[params]
|
||||||
|
|
||||||
compress/mode=0
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
compress/lossy_quality=0.7
|
compress/lossy_quality=0.7
|
||||||
compress/hdr_compression=1
|
compress/hdr_compression=1
|
||||||
compress/bptc_ldr=0
|
|
||||||
compress/normal_map=0
|
compress/normal_map=0
|
||||||
compress/channel_pack=0
|
compress/channel_pack=0
|
||||||
mipmaps/generate=false
|
mipmaps/generate=false
|
||||||
|
@@ -10,9 +10,9 @@ config_version=5
|
|||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Godot Mono thirdperson controller"
|
config/name="Godot .NET thirdperson controller"
|
||||||
run/main_scene="res://scenes/main.tscn"
|
run/main_scene="res://scenes/main.tscn"
|
||||||
config/features=PackedStringArray("4.0", "Forward Plus")
|
config/features=PackedStringArray("4.2", "C#", "Forward Plus")
|
||||||
boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1)
|
boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1)
|
||||||
boot_splash/show_image=false
|
boot_splash/show_image=false
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# Godot Mono thirdperson controller
|
# Godot 4.0 .NET thirdperson controller
|
||||||
This is a working thirdperson controller made in the mono version of godot with C# <br>
|
This is a working thirdperson controller made in the .NET version of Godot 4.0 with C# <br>
|
||||||
Currently running in Godot 4 beta 16<br>
|
|
||||||
<br>
|
<br>
|
||||||
|
[My Discord Server](https://discord.com/invite/EBdaTefpWy) <br><br>
|
||||||
Demo video: https://www.youtube.com/watch?v=qTzU90Vj3Nw<br>
|
Demo video: https://www.youtube.com/watch?v=qTzU90Vj3Nw<br>
|
||||||
<br>
|
<br>
|
||||||
<img width="200px" src="https://raw.githubusercontent.com/vaporvee/gd-mono-thirdpersoncontroller/master/icon.png">
|
<img width="200px" src="https://raw.githubusercontent.com/vaporvee/gd-mono-thirdpersoncontroller/master/icon.png">
|
||||||
|
@@ -5,6 +5,8 @@ public partial class player : CharacterBody3D
|
|||||||
public Vector3 direction;
|
public Vector3 direction;
|
||||||
public Vector2 gpCamVector;
|
public Vector2 gpCamVector;
|
||||||
public bool gamepadMode;
|
public bool gamepadMode;
|
||||||
|
private Marker3D cameraCenter {get; set;}
|
||||||
|
private MeshInstance3D collisionBody {get; set;}
|
||||||
[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;
|
||||||
@@ -12,6 +14,11 @@ public partial class player : CharacterBody3D
|
|||||||
[Export(PropertyHint.Range, "-90,0,1")] float minCamPitch = -50f;
|
[Export(PropertyHint.Range, "-90,0,1")] float minCamPitch = -50f;
|
||||||
[Export(PropertyHint.Range, "0,90,1")] float maxCamPitch = 30f;
|
[Export(PropertyHint.Range, "0,90,1")] float maxCamPitch = 30f;
|
||||||
|
|
||||||
|
public override void _Ready() {
|
||||||
|
cameraCenter = GetNode<Marker3D>("camera_center");
|
||||||
|
collisionBody = GetNode<MeshInstance3D>("collision/body");
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
//uncapturing the mouse disables PC movement but still simulates gravity
|
//uncapturing the mouse disables PC movement but still simulates gravity
|
||||||
@@ -22,19 +29,19 @@ public partial class player : CharacterBody3D
|
|||||||
maybe rotate extra collisions separately for invisible lag that may occur**/
|
maybe rotate extra collisions separately for invisible lag that may occur**/
|
||||||
if (direction != Vector3.Zero && Input.MouseMode == Input.MouseModeEnum.Captured | gamepadMode)
|
if (direction != Vector3.Zero && Input.MouseMode == Input.MouseModeEnum.Captured | gamepadMode)
|
||||||
{
|
{
|
||||||
Vector3 bodyRotation = GetNode<MeshInstance3D>("collision/body").Rotation;
|
Vector3 bodyRotation = collisionBody.Rotation;
|
||||||
bodyRotation.Y = Mathf.LerpAngle(bodyRotation.Y,Mathf.Atan2(-direction.X, -direction.Z), (float)delta * speed);
|
bodyRotation.Y = Mathf.LerpAngle(bodyRotation.Y,Mathf.Atan2(-direction.X, -direction.Z), (float)delta * speed);
|
||||||
GetNode<MeshInstance3D>("collision/body").Rotation = bodyRotation;
|
collisionBody.Rotation = bodyRotation;
|
||||||
}
|
}
|
||||||
//camera gamepad part (needs constant movement so _Input event wouldn't work with this like mouseinput)
|
//camera gamepad part (needs constant movement so _Input event wouldn't work with this like mouseinput)
|
||||||
gpCamVector = Input.GetVector("gp_cam_left", "gp_cam_right", "gp_cam_up", "gp_cam_down");
|
gpCamVector = Input.GetVector("gp_cam_left", "gp_cam_right", "gp_cam_up", "gp_cam_down");
|
||||||
if(gpCamVector != Vector2.Zero)
|
if(gpCamVector != Vector2.Zero)
|
||||||
{
|
{
|
||||||
Vector3 camRot = GetNode<Marker3D>("camera_center").RotationDegrees;
|
Vector3 camRot = cameraCenter.RotationDegrees;
|
||||||
camRot.Y -= gpCamVector.X * camSensitivity * (float)delta * 500;
|
camRot.Y -= gpCamVector.X * camSensitivity * (float)delta * 500;
|
||||||
camRot.X -= gpCamVector.Y * camSensitivity * (float)delta * 500;
|
camRot.X -= gpCamVector.Y * camSensitivity * (float)delta * 500;
|
||||||
camRot.X = Mathf.Clamp(camRot.X, minCamPitch, maxCamPitch); //prevents camera from going endlessly around the player
|
camRot.X = Mathf.Clamp(camRot.X, minCamPitch, maxCamPitch); //prevents camera from going endlessly around the player
|
||||||
GetNode<Marker3D>("camera_center").RotationDegrees = camRot;
|
cameraCenter.RotationDegrees = camRot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
@@ -65,13 +72,13 @@ public partial class player : CharacterBody3D
|
|||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
gamepadMode = @event is InputEventJoypadButton | @event is InputEventJoypadMotion;
|
gamepadMode = @event is InputEventJoypadButton | @event is InputEventJoypadMotion;
|
||||||
Vector3 camRot = GetNode<Marker3D>("camera_center").RotationDegrees;
|
Vector3 camRot = cameraCenter.RotationDegrees;
|
||||||
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured)
|
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured)
|
||||||
{
|
{
|
||||||
camRot.Y -= mouseMotion.Relative.X * camSensitivity;
|
camRot.Y -= mouseMotion.Relative.X * camSensitivity;
|
||||||
camRot.X -= mouseMotion.Relative.Y * camSensitivity;
|
camRot.X -= mouseMotion.Relative.Y * camSensitivity;
|
||||||
}
|
}
|
||||||
camRot.X = Mathf.Clamp(camRot.X, minCamPitch, maxCamPitch); //prevents camera from going endlessly around the player
|
camRot.X = Mathf.Clamp(camRot.X, minCamPitch, maxCamPitch); //prevents camera from going endlessly around the player
|
||||||
GetNode<Marker3D>("camera_center").RotationDegrees = camRot;
|
cameraCenter.RotationDegrees = camRot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user