godot third person player controller godot 4.4 c# using Godot; public partial class…
- User
godot third person player controller godot 4.4 c#
using Godot;
public partial class Player : CharacterBody3D { [Export] public float MoveSpeed = 6.0f; [Export] public float JumpForce = 10.0f; [Export] public float Gravity = -9.8f; [Export] public float RotationSpeed = 5.0f;
codeprivate Vector3 _velocity = Vector3.Zero; private Vector3 _inputDirection = Vector3.Zero; public override void _PhysicsProcess(double delta) { // Capture input _inputDirection = Vector3.Zero; if (Input.IsActionPressed("move_forward")) _inputDirection.Z -= 1; if (Input.IsActionPressed("move_backward")) _inputDirection.Z += 1; if (Input.IsActionPressed("move_left")) _inputDirection.X -= 1; if (Input.IsActionPressed("move_right")) _inputDirection.X += 1; // Normalize the input direction if (_inputDirection != Vector3.Zero) { _inputDirection = _inputDirection.Normalized(); } // Convert input direction to global space _inputDirection = GlobalTransform.Basis * _inputDirection; // Set horizontal movement velocity _velocity.X = _inputDirection.X * MoveSpeed; _velocity.Z = _inputDirection.Z * MoveSpeed; // Apply gravity if (!IsOnFloor()) { _velocity.Y += Gravity * (float)delta; } // Handle jumping if (Input.IsActionJustPressed("jump") && IsOnFloor()) { _velocity.Y = JumpForce; } // Move the character MoveAndSlide(); // Rotate the character towards the movement direction if (_inputDirection.LengthSquared() > 0.01f) { var targetRotation = _inputDirection.Normalized(); var targetYaw = Mathf.Atan2(targetRotation.X, targetRotation.Z); Rotation = new Vector3(0, Mathf.LerpAngle(Rotation.Y, targetYaw, RotationSpeed * (float)delta), 0); } } - Assistant
- User
from godot 4.0 MoveAndSlide(); is the only correct code for this function
- Assistant
- User
CS0029: Cannot implicitly convert type 'bool' to 'Godot.Vector3' D:\Godot\Zombie\Scripts\Player.cs(67,15)
- Assistant
- User
E 0:00:16:0272 NativeCalls.cs:7266 @ Godot.GodotObject Godot.NativeCalls.godot_icall_1_823(nint, nint, Godot.NativeInterop.godot_node_path): Node not found: "CameraPath/CameraNode" (relative to "/root/Playground/Player/CharacterBody3D"). <C++ Error> Method/function failed. Returning: nullptr <C++ Source> scene/main/node.cpp:1875 @ get_node() NativeCalls.cs:7266 @ Godot.GodotObject Godot.NativeCalls.godot_icall_1_823(nint, nint, Godot.NativeInterop.godot_node_path) Node.cs:900 @ Godot.Node Godot.Node.GetNode(Godot.NodePath) NodeExtensions.cs:47 @ T Godot.Node.GetNode(Godot.NodePath) Player.cs:35 @ void Player._PhysicsProcess(double) Node.cs:2508 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) Node3D.cs:1098 @ bool Godot.Node3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CollisionObject3D.cs:607 @ bool Godot.CollisionObject3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) PhysicsBody3D.cs:239 @ bool Godot.PhysicsBody3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CharacterBody3D.cs:797 @ bool Godot.CharacterBody3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) Player_ScriptMethods.generated.cs:38 @ bool Player.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
- Assistant