Compare commits

..

8 Commits

Author SHA1 Message Date
d59047d0ae remove template project tag
All checks were successful
Linux arm64 / Build (push) Successful in 56s
2024-08-12 13:28:25 +02:00
e93afbeaf1 fix warnings 2024-08-12 11:51:33 +02:00
d9aba1924f third persson prototype 2024-08-12 11:45:42 +02:00
ba66b7b3b4 remove icon import file 2024-08-12 11:45:17 +02:00
26b62dbdd7 ignore import files 2024-08-12 11:45:00 +02:00
fb0a4fc7a5 remove gdexample 2024-08-12 11:44:52 +02:00
cdbe8c3114 add debug define 2024-08-12 11:43:02 +02:00
35708456d4 add clang format 2024-08-12 11:42:47 +02:00
31 changed files with 24135 additions and 128 deletions

37
.clang-format Normal file
View File

@@ -0,0 +1,37 @@
Language: Cpp
BasedOnStyle: LLVM
AlignAfterOpenBracket: DontAlign
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
PointerAlignment: Left
SortIncludes: true
SpacesBeforeTrailingComments: 2
UseTab: Always
MaxEmptyLinesToKeep: 5
TabWidth: 4
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
IndentWidth: 4
IndentCaseLabels: true
ColumnLimit: 135
AlwaysBreakTemplateDeclarations: Yes
AllowShortFunctionsOnASingleLine: Empty
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true

1
.gitignore vendored
View File

@@ -14,6 +14,7 @@ build/
*.obj *.obj
*.lib *.lib
*.TMP *.TMP
*.import
godot/.godot godot/.godot
godot/lib godot/lib

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,92 @@
[gd_scene load_steps=18 format=3 uid="uid://coue2qehpn4fr"]
[ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="1_hwes2"]
[ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_rrvcb"]
[ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="2_087ax"]
[ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="3_qkav0"]
[ext_resource type="PackedScene" path="res://Scenes/Characters/player.tscn" id="5_2382e"]
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"]
panorama = ExtResource("1_rrvcb")
[sub_resource type="Sky" id="Sky_5ngqa"]
sky_material = SubResource("PanoramaSkyMaterial_6c4vd")
[sub_resource type="Environment" id="Environment_ctwiv"]
background_mode = 2
sky = SubResource("Sky_5ngqa")
tonemap_mode = 2
glow_enabled = true
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ajchh"]
albedo_texture = ExtResource("1_hwes2")
uv1_triplanar = true
[sub_resource type="PlaneMesh" id="PlaneMesh_mmup0"]
material = SubResource("StandardMaterial3D_ajchh")
size = Vector2(50, 50)
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_26ptr"]
data = PackedVector3Array(25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, 25, -25, 0, -25, 25, 0, -25)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jkvud"]
albedo_texture = ExtResource("2_087ax")
uv1_triplanar = true
[sub_resource type="BoxMesh" id="BoxMesh_plpqy"]
material = SubResource("StandardMaterial3D_jkvud")
size = Vector3(10, 3, 1)
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_v7prx"]
data = PackedVector3Array(-5, 1.5, 0.5, 5, 1.5, 0.5, -5, -1.5, 0.5, 5, 1.5, 0.5, 5, -1.5, 0.5, -5, -1.5, 0.5, 5, 1.5, -0.5, -5, 1.5, -0.5, 5, -1.5, -0.5, -5, 1.5, -0.5, -5, -1.5, -0.5, 5, -1.5, -0.5, 5, 1.5, 0.5, 5, 1.5, -0.5, 5, -1.5, 0.5, 5, 1.5, -0.5, 5, -1.5, -0.5, 5, -1.5, 0.5, -5, 1.5, -0.5, -5, 1.5, 0.5, -5, -1.5, -0.5, -5, 1.5, 0.5, -5, -1.5, 0.5, -5, -1.5, -0.5, 5, 1.5, 0.5, -5, 1.5, 0.5, 5, 1.5, -0.5, -5, 1.5, 0.5, -5, 1.5, -0.5, 5, 1.5, -0.5, -5, -1.5, 0.5, 5, -1.5, 0.5, -5, -1.5, -0.5, 5, -1.5, 0.5, 5, -1.5, -0.5, -5, -1.5, -0.5)
[sub_resource type="PrismMesh" id="PrismMesh_0l7qq"]
left_to_right = -2.0
size = Vector3(5, 5, 5)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pfpgv"]
albedo_texture = ExtResource("3_qkav0")
uv1_triplanar = true
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"]
data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5)
[node name="Prototype" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_ctwiv")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866026, -0.433013, 0.249999, 0.5, -0.75, 0.433012, -1.3411e-07, 0.499999, 0.866026, 0, 0, 0)
shadow_enabled = true
[node name="Floor" type="MeshInstance3D" parent="."]
mesh = SubResource("PlaneMesh_mmup0")
[node name="StaticBody3D" type="StaticBody3D" parent="Floor"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_26ptr")
[node name="Wall" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, -3)
mesh = SubResource("BoxMesh_plpqy")
[node name="StaticBody3D" type="StaticBody3D" parent="Wall"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_v7prx")
[node name="Slope" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 1, 4)
mesh = SubResource("PrismMesh_0l7qq")
surface_material_override/0 = SubResource("StandardMaterial3D_pfpgv")
[node name="StaticBody3D" type="StaticBody3D" parent="Slope"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Slope/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_rit6o")
[node name="Player" parent="." instance=ExtResource("5_2382e")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0130468, 0)
velocity = Vector3(0, 0, 0)

View File

@@ -0,0 +1,63 @@
extends CharacterBody3D
const LERP_VALUE : float = 0.15
var snap_vector : Vector3 = Vector3.DOWN
var speed : float
@export_group("Movement variables")
@export var walk_speed : float = 2.0
@export var run_speed : float = 5.0
@export var jump_strength : float = 15.0
@export var gravity : float = 50.0
const ANIMATION_BLEND : float = 7.0
@onready var player_mesh : Node3D = $Mesh
@onready var spring_arm_pivot : Node3D = $SpringArmPivot
@onready var animator : AnimationTree = $AnimationTree
func _physics_process(delta):
var move_direction : Vector3 = Vector3.ZERO
move_direction.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
move_direction.z = Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forwards")
move_direction = move_direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
velocity.y -= gravity * delta
if Input.is_action_pressed("run"):
speed = run_speed
else:
speed = walk_speed
velocity.x = move_direction.x * speed
velocity.z = move_direction.z * speed
if move_direction:
player_mesh.rotation.y = lerp_angle(player_mesh.rotation.y, atan2(velocity.x, velocity.z), LERP_VALUE)
var just_landed := is_on_floor() and snap_vector == Vector3.ZERO
var is_jumping := is_on_floor() and Input.is_action_just_pressed("jump")
if is_jumping:
velocity.y = jump_strength
snap_vector = Vector3.ZERO
elif just_landed:
snap_vector = Vector3.DOWN
apply_floor_snap()
move_and_slide()
animate(delta)
func animate(delta):
if is_on_floor():
animator.set("parameters/ground_air_transition/transition_request", "grounded")
if velocity.length() > 0:
if speed == run_speed:
animator.set("parameters/iwr_blend/blend_amount", lerp(animator.get("parameters/iwr_blend/blend_amount"), 1.0, delta * ANIMATION_BLEND))
else:
animator.set("parameters/iwr_blend/blend_amount", lerp(animator.get("parameters/iwr_blend/blend_amount"), 0.0, delta * ANIMATION_BLEND))
else:
animator.set("parameters/iwr_blend/blend_amount", lerp(animator.get("parameters/iwr_blend/blend_amount"), -1.0, delta * ANIMATION_BLEND))
else:
animator.set("parameters/ground_air_transition/transition_request", "air")

View File

@@ -0,0 +1,30 @@
extends Node3D
@export_group("FOV")
@export var change_fov_on_run : bool
@export var normal_fov : float = 75.0
@export var run_fov : float = 90.0
const CAMERA_BLEND : float = 0.05
@onready var spring_arm : SpringArm3D = $SpringArm3D
@onready var camera : Camera3D = $SpringArm3D/Camera3D
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _unhandled_input(event):
if event is InputEventMouseMotion:
rotate_y(-event.relative.x * 0.005)
spring_arm.rotate_x(-event.relative.y * 0.005)
spring_arm.rotation.x = clamp(spring_arm.rotation.x, -PI/4, PI/4)
func _physics_process(_delta):
if change_fov_on_run:
if owner.is_on_floor():
if Input.is_action_pressed("run"):
camera.fov = lerp(camera.fov, run_fov, CAMERA_BLEND)
else:
camera.fov = lerp(camera.fov, normal_fov, CAMERA_BLEND)
else:
camera.fov = lerp(camera.fov, normal_fov, CAMERA_BLEND)

View File

@@ -1 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z" fill="#478cbf"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg> <svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 949 B

After

Width:  |  Height:  |  Size: 950 B

View File

@@ -1,37 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cuend5rtkhbnp"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -1,10 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://uiwigxsdnci1"]
[ext_resource type="Texture2D" uid="uid://cuend5rtkhbnp" path="res://icon.svg" id="1_q81dj"]
[node name="Node2D" type="Node2D"]
[node name="GDExample" type="GDExample" parent="."]
position = Vector2(5.20978, 6.34048)
texture = ExtResource("1_q81dj")
centered = false

View File

@@ -11,6 +11,40 @@ config_version=5
[application] [application]
config/name="Blitz3" config/name="Blitz3"
run/main_scene="res://main.tscn" config/tags=PackedStringArray()
run/main_scene="res://Scenes/Levels/prototype.tscn"
config/features=PackedStringArray("4.2", "Forward Plus") config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[input]
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
]
}
move_forwards={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
]
}
move_backwards={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
]
}
run={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
]
}

111
src/Player.cpp Normal file
View File

@@ -0,0 +1,111 @@
#include "Player.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/input_map.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
static const float WalkSpeed = 2.0;
static const float RunSpeed = 5.0;
static const float JumpStrength = 15.0;
static const float Gravity = 50.0;
static const float LerpValue = 0.15;
static const float AnimationBlend = 7.0;
namespace blitz {
void Player::_bind_methods() {}
Player::Player() {}
Player::~Player() {}
void Player::_ready() {
godot::InputMap::get_singleton()->load_from_project_settings();
m_PlayerMesh = Object::cast_to<godot::Node3D>(get_child(0));
m_SpringArmPivot = Object::cast_to<godot::Node3D>(get_child(2));
m_AnimationTree = Object::cast_to<godot::AnimationTree>(get_child(4));
DEV_ASSERT(m_PlayerMesh);
DEV_ASSERT(m_SpringArmPivot);
DEV_ASSERT(m_AnimationTree);
apply_floor_snap();
animate(0);
}
void Player::_physics_process(float delta) {
if (godot::Engine::get_singleton()->is_editor_hint())
return;
auto* Input = godot::Input::get_singleton();
godot::Vector3 move_direction{0, 0, 0};
move_direction.x = Input->get_action_strength("move_right") - Input->get_action_strength("move_left");
move_direction.z = Input->get_action_strength("move_backwards") - Input->get_action_strength("move_forwards");
move_direction = move_direction.rotated({0, 1, 0}, m_SpringArmPivot->get_rotation().y);
godot::Vector3 newVelocity = get_velocity();
newVelocity.y -= Gravity * delta;
set_velocity(newVelocity);
if (Input->is_action_pressed("run"))
m_Speed = RunSpeed;
else
m_Speed = WalkSpeed;
newVelocity = get_velocity();
newVelocity.x = move_direction.x * m_Speed;
newVelocity.z = move_direction.z * m_Speed;
set_velocity(newVelocity);
if (move_direction != godot::Vector3{0, 0, 0}) {
godot::Vector3 newRotation = m_PlayerMesh->get_rotation();
newRotation.y = godot::UtilityFunctions::lerp_angle(
newRotation.y, godot::UtilityFunctions::atan2(get_velocity().x, get_velocity().z), LerpValue);
m_PlayerMesh->set_rotation(newRotation);
}
bool justLanded = is_on_floor() && m_SnapVector == godot::Vector3{0, 0, 0};
bool isJumping = is_on_floor() && Input->is_action_just_pressed("jump");
if (isJumping) {
newVelocity = get_velocity();
newVelocity.y = JumpStrength;
set_velocity(newVelocity);
m_SnapVector.zero();
} else if (justLanded) {
m_SnapVector = {0, -1, 0};
}
apply_floor_snap();
move_and_slide();
animate(delta);
}
void Player::animate(float delta) {
if (is_on_floor()) {
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded");
if (get_velocity().length() > 0) {
if (m_Speed == RunSpeed) {
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
godot::UtilityFunctions::lerp(
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend));
} else {
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
godot::UtilityFunctions::lerp(
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 0.0, delta * AnimationBlend));
}
} else {
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
godot::UtilityFunctions::lerp(
m_AnimationTree->get("parameters/iwr_blend/blend_amount"), -1.0, delta * AnimationBlend));
}
} else {
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "air");
}
}
} // namespace blitz

37
src/Player.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include <godot_cpp/classes/animation_tree.hpp>
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
namespace blitz {
class Player : public godot::CharacterBody3D {
GDCLASS(Player, godot::CharacterBody3D);
protected:
static void _bind_methods();
public:
Player();
~Player();
void _ready();
void _physics_process(float delta);
void animate(float delta);
private:
godot::Node3D* m_PlayerMesh;
godot::Node3D* m_SpringArmPivot;
godot::AnimationTree* m_AnimationTree;
godot::Vector3 m_SnapVector;
float m_Speed;
/*
@onready var player_mesh : Node3D = $Mesh
@onready var spring_arm_pivot : Node3D = $SpringArmPivot
@onready var animator : AnimationTree = $AnimationTree
*/
};
} // namespace blitz

65
src/SpringArmPivot.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "SpringArmPivot.h"
#include "Player.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
#include <godot_cpp/classes/spring_arm3d.hpp>
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
static const float NormalFov = 75.0;
static const float RunFov = 90.0;
static const float CameraBlend = 0.05;
namespace blitz {
void SpringArmPivot::_bind_methods() {
godot::ClassDB::bind_method(godot::D_METHOD("get_dynfov"), &SpringArmPivot::IsFovDynamic);
godot::ClassDB::bind_method(godot::D_METHOD("set_dynfov", "dynamic_fov"), &SpringArmPivot::SetDynamicFov);
ADD_PROPERTY(godot::PropertyInfo(godot::Variant::BOOL, "dynamic_fov"), "set_dynfov", "get_dynfov");
}
SpringArmPivot::SpringArmPivot() {}
SpringArmPivot::~SpringArmPivot() {}
void SpringArmPivot::_ready() {
m_SpringArm = Object::cast_to<godot::SpringArm3D>(get_child(0));
m_Camera = Object::cast_to<godot::Camera3D>(m_SpringArm->get_child(0));
DEV_ASSERT(m_SpringArm);
DEV_ASSERT(m_Camera);
if (!godot::Engine::get_singleton()->is_editor_hint()) {
godot::Input::get_singleton()->set_mouse_mode(godot::Input::MOUSE_MODE_CAPTURED);
}
}
void SpringArmPivot::_unhandled_input(const godot::Ref<godot::InputEvent>& p_event) {
auto* event = Object::cast_to<godot::InputEventMouseMotion>(p_event.ptr());
if (event) {
rotate_y(-event->get_relative().x * 0.005);
m_SpringArm->rotate_x(-event->get_relative().y * 0.005);
godot::Vector3 rotationClamped = m_SpringArm->get_rotation();
rotationClamped.x = godot::UtilityFunctions::clamp(rotationClamped.x, -Math_PI / 4, Math_PI / 4);
m_SpringArm->set_rotation(rotationClamped);
}
}
void SpringArmPivot::_physics_process(float delta) {
if (m_DynamicFOV) {
auto* parent = Object::cast_to<Player>(get_owner());
if (parent->is_on_floor()) {
if (godot::Input::get_singleton()->is_action_pressed("run")) {
m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), RunFov, CameraBlend));
} else {
m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), NormalFov, CameraBlend));
}
} else {
m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), NormalFov, CameraBlend));
}
}
}
} // namespace blitz

38
src/SpringArmPivot.h Normal file
View File

@@ -0,0 +1,38 @@
#pragma once
#include <godot_cpp/classes/input_event.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/spring_arm3d.hpp>
#include <godot_cpp/classes/camera3d.hpp>
namespace blitz {
class SpringArmPivot : public godot::Node3D {
GDCLASS(SpringArmPivot, godot::Node3D);
protected:
static void _bind_methods();
public:
SpringArmPivot();
~SpringArmPivot();
void _ready();
void _unhandled_input(const godot::Ref<godot::InputEvent>& p_event);
void _physics_process(float delta);
void SetDynamicFov(bool fov) {
m_DynamicFOV = fov;
}
bool IsFovDynamic() const {
return m_DynamicFOV;
}
private:
godot::SpringArm3D* m_SpringArm;
godot::Camera3D* m_Camera;
bool m_DynamicFOV = false;
};
} // namespace blitz

View File

@@ -1,28 +0,0 @@
#include "gdexample.h"
#include <godot_cpp/core/class_db.hpp>
using namespace godot;
void GDExample::_bind_methods() {
// ClassDB::bind_method(D_METHOD("_process", "delta"), &GDExample::_process);
}
GDExample::GDExample()
{
time_passed = 0.0;
}
GDExample::~GDExample() {}
void GDExample::_process(float delta)
{
time_passed += delta;
auto new_position = Vector2(
10.0 + (10.0 * sin(time_passed * 2.0)),
10.0 + (10.0 * cos(time_passed * 1.5)));
set_position(new_position);
}

View File

@@ -1,24 +0,0 @@
#ifndef GDEXAMPLE_H
#define GDEXAMPLE_H
#include <godot_cpp/classes/sprite2d.hpp>
namespace godot
{
class GDExample : public Sprite2D
{
GDCLASS(GDExample, Sprite2D)
private:
double time_passed;
protected:
static void _bind_methods();
public:
GDExample();
~GDExample();
void _process(float delta);
};
}
#endif

View File

@@ -1,6 +1,7 @@
#include "register_types.h" #include "register_types.h"
#include "gdexample.h" #include "Player.h"
#include "SpringArmPivot.h"
#include <gdextension_interface.h> #include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp> #include <godot_cpp/core/defs.hpp>
@@ -8,37 +9,29 @@
using namespace godot; using namespace godot;
void initialize_example_module(ModuleInitializationLevel p_level) void initialize_example_module(ModuleInitializationLevel p_level) {
{ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) return;
{ }
return;
}
ClassDB::register_class<GDExample>(); ClassDB::register_class<blitz::Player>();
ClassDB::register_class<blitz::SpringArmPivot>();
} }
void uninitialize_example_module(ModuleInitializationLevel p_level) void uninitialize_example_module(ModuleInitializationLevel p_level) {
{ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) return;
{ }
return;
}
} }
extern "C" extern "C"
{ GDExtensionBool GDE_EXPORT library_init(GDExtensionInterfaceGetProcAddress p_get_proc, const GDExtensionClassLibraryPtr p_library,
GDExtensionBool GDE_EXPORT library_init( GDExtensionInitialization* r_initialization) {
GDExtensionInterfaceGetProcAddress p_get_proc, godot::GDExtensionBinding::InitObject init_obj(p_get_proc, p_library, r_initialization);
const GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization)
{
godot::GDExtensionBinding::InitObject init_obj(p_get_proc, p_library, r_initialization);
init_obj.register_initializer(initialize_example_module); init_obj.register_initializer(initialize_example_module);
init_obj.register_terminator(uninitialize_example_module); init_obj.register_terminator(uninitialize_example_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE); init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init(); return init_obj.init();
} }
}

View File

@@ -1,3 +1,9 @@
if is_mode("debug") then
add_defines("DEBUG_ENABLED")
end
-- more on https://xmake.io/#/manual/project_target -- more on https://xmake.io/#/manual/project_target
target(PROJECT_NAME) target(PROJECT_NAME)
set_kind("shared") set_kind("shared")