linux
Sascha 2024-02-08 11:43:30 +07:00
parent 0e2d4f3636
commit 74fabb1b9a
5 changed files with 70402 additions and 70293 deletions

@ -0,0 +1,39 @@
using System;
using Godot;
namespace DRPGActionGame.Player;
public partial class CameraController : Node3D {
[Export] private float sensitivity = 5f;
[Export] private SpringArm3D springArm3D;
private const float maxXRot = .25f;
private const float maxZoom = 2f;
private const float minZoom = 10f;
public override void _Ready() => Input.MouseMode = Input.MouseModeEnum.Captured;
// public override void _Process(double delta) => GlobalPosition = GetParent<Node3D>().GlobalPosition;
public override void _Input(InputEvent @event) {
switch (@event) {
case InputEventMouseMotion inputEventMouseMotion: {
float xRot = Mathf.Clamp(Rotation.X - inputEventMouseMotion.Relative.Y / 1000 * sensitivity, -maxXRot, +maxXRot);
float yRot = Rotation.Y - inputEventMouseMotion.Relative.X / 1000 * sensitivity;
Rotation = new(xRot, yRot, 0);
break;
}
case InputEventMouseButton inputEventMouseButton: {
if (inputEventMouseButton.ButtonIndex == MouseButton.WheelDown) {
if (springArm3D.SpringLength < minZoom)
springArm3D.SpringLength += 0.1f;
}
else if (inputEventMouseButton.ButtonIndex == MouseButton.WheelUp) {
if (springArm3D.SpringLength > maxZoom)
springArm3D.SpringLength -= 0.1f;
}
break;
}
}
}
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,46 @@
using Godot;
namespace DRPGActionGame.Player;
public partial class Player2 : CharacterBody3D
{
private const float SPEED = 5.0f;
private const float JUMP_VELOCITY = 4.5f;
// Get the gravity from the project settings to be synced with RigidBody nodes.
private float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
[Export] private AnimationPlayer animationPlayer;
public override void _PhysicsProcess(double delta)
{
Vector3 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
velocity.Y -= gravity * (float)delta;
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
velocity.Y = JUMP_VELOCITY;
// Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions.
Vector2 inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
if (direction != Vector3.Zero)
{
animationPlayer.Play("Walking_A");
velocity.X = direction.X * SPEED;
velocity.Z = direction.Z * SPEED;
}
else {
animationPlayer.Play("Idle");
velocity.X = Mathf.MoveToward(Velocity.X, 0, SPEED);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, SPEED);
}
Velocity = velocity;
MoveAndSlide();
}
}

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://dfy2rn0ryl0gw"] [gd_scene load_steps=7 format=3 uid="uid://dfy2rn0ryl0gw"]
[ext_resource type="PackedScene" uid="uid://cqgw85i74nek0" path="res://Player/Player.tscn" id="1_ks6w4"] [ext_resource type="PackedScene" uid="uid://cbn878rbtj1a8" path="res://Player/Player2.tscn" id="2_6l1py"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_lcthy"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_lcthy"]
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
@ -37,6 +37,6 @@ mesh = SubResource("BoxMesh_fdw8w")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"]
shape = SubResource("BoxShape3D_aivjm") shape = SubResource("BoxShape3D_aivjm")
[node name="Player" parent="." node_paths=PackedStringArray("animationPlayer") instance=ExtResource("1_ks6w4")] [node name="Player2" parent="." node_paths=PackedStringArray("animationPlayer") instance=ExtResource("2_6l1py")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.24748, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.55437, 0.835652, -1.61826)
animationPlayer = NodePath("Character/AnimationPlayer") animationPlayer = NodePath("Skeleton_Minion/AnimationPlayer")