mirror of
https://github.com/FOSS-Supremacy/OpenLiberty.git
synced 2025-04-28 20:07:57 +03:00
Merge pull request #22 from a6xdev/main
Implement Third-Person Character Controller
This commit is contained in:
commit
1c94bcfcc4
14 changed files with 3921 additions and 10 deletions
Binary file not shown.
Binary file not shown.
BIN
addons/Third-Person-Controller-main/Assets/Animations/02_Run.res
Normal file
BIN
addons/Third-Person-Controller-main/Assets/Animations/02_Run.res
Normal file
Binary file not shown.
Binary file not shown.
BIN
addons/Third-Person-Controller-main/Assets/Animations/04_Air.res
Normal file
BIN
addons/Third-Person-Controller-main/Assets/Animations/04_Air.res
Normal file
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,36 @@
|
|||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://dbfbwpvx4kmh8"
|
||||
path="res://.godot/imported/Object_Character.glb-73553dae647ff03171bea1f68cccf3d2.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/Third-Person-Controller-main/Assets/Models/Characters/Object_Character.glb"
|
||||
dest_files=["res://.godot/imported/Object_Character.glb-73553dae647ff03171bea1f68cccf3d2.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type=""
|
||||
nodes/root_name=""
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
nodes/import_as_skeleton_bones=false
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=1
|
||||
meshes/lightmap_texel_size=0.2
|
||||
meshes/force_disable_compression=false
|
||||
skins/use_named_skins=true
|
||||
animation/import=true
|
||||
animation/fps=30
|
||||
animation/trimming=false
|
||||
animation/remove_immutable_tracks=true
|
||||
animation/import_rest_as_RESET=false
|
||||
import_script/path=""
|
||||
_subresources={}
|
||||
gltf/naming_version=1
|
||||
gltf/embedded_image_handling=0
|
|
@ -0,0 +1,64 @@
|
|||
extends CharacterBody3D
|
||||
class_name Player
|
||||
|
||||
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("player_right") - Input.get_action_strength("player_left")
|
||||
move_direction.z = Input.get_action_strength("player_backward") - Input.get_action_strength("player_forward")
|
||||
move_direction = move_direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
|
||||
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
if Input.is_action_pressed("player_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("player_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")
|
|
@ -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)
|
3777
prefabs/actors/player/ThirdPersonPlayer.tscn
Normal file
3777
prefabs/actors/player/ThirdPersonPlayer.tscn
Normal file
File diff suppressed because one or more lines are too long
|
@ -298,6 +298,8 @@ bones/24/scale = Vector3(1, 1, 1)
|
|||
mesh = SubResource("ArrayMesh_7xqwr")
|
||||
skin = SubResource("Skin_kcspo")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="mesh/MaleArm"]
|
||||
|
||||
[node name="collision" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_eidr1")
|
||||
|
||||
|
|
|
@ -493,8 +493,10 @@ shadow_mesh = SubResource("ArrayMesh_xnix1")
|
|||
|
||||
[node name="VehicleTemplate" type="VehicleBody3D"]
|
||||
script = ExtResource("1_xfu4b")
|
||||
state = null
|
||||
MAX_STEER = 1.0
|
||||
ENGINE_POWER = 100
|
||||
DECELERATION_RATE = null
|
||||
|
||||
[node name="Car" type="Node3D" parent="."]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://bpy61iddtbrdu"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://yo0220jx0v3r" path="res://prefabs/actors/player/obj_player.tscn" id="1_glk4w"]
|
||||
[ext_resource type="PackedScene" uid="uid://cr2ersq7g6q6f" path="res://prefabs/actors/player/ThirdPersonPlayer.tscn" id="1_lnyc1"]
|
||||
[ext_resource type="PackedScene" uid="uid://d2u8vbkvktl7g" path="res://prefabs/vehicles/VehicleTemplate.tscn" id="2_np362"]
|
||||
[ext_resource type="Texture2D" uid="uid://t08wbyrcvylh" path="res://assets/textures/GroundPrototype/Dark/texture_08.png" id="2_u7u28"]
|
||||
[ext_resource type="Material" uid="uid://up5atx65jyxf" path="res://assets/materials/prototype/orange.tres" id="3_6s1rt"]
|
||||
|
@ -29,8 +29,7 @@ sky = SubResource("Sky_xashb")
|
|||
|
||||
[node name="actors" type="Node" parent="."]
|
||||
|
||||
[node name="obj_player" parent="actors" instance=ExtResource("1_glk4w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
[node name="Player" parent="actors" instance=ExtResource("1_lnyc1")]
|
||||
|
||||
[node name="Vehicle" type="Node" parent="."]
|
||||
|
||||
|
@ -59,4 +58,5 @@ environment = SubResource("Environment_q6cjc")
|
|||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.800888, 0.598814, 0, -0.598814, 0.800888, 0, 4.4221, 0)
|
||||
shadow_enabled = true
|
||||
visible = false
|
||||
shadow_enabled = true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
extends CharacterBody3D
|
||||
class_name Player
|
||||
#class_name Player
|
||||
|
||||
var move_dir = Vector3.ZERO
|
||||
var motion = Vector3.ZERO
|
||||
|
@ -37,11 +37,11 @@ var rotation_speed = 10.0 # for player rotation.
|
|||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
cam_pivot.rotate_y(-event.relative.x * sensitivity/2)
|
||||
spring_arm_3d.rotate_x(-event.relative.y * sensitivity/2)
|
||||
spring_arm_3d.rotation.x = clamp(spring_arm_3d.rotation.x, -PI/3, PI/5)
|
||||
#func _input(event: InputEvent) -> void:
|
||||
#if event is InputEventMouseMotion:
|
||||
#cam_pivot.rotate_y(-event.relative.x * sensitivity/2)
|
||||
#spring_arm_3d.rotate_x(-event.relative.y * sensitivity/2)
|
||||
#spring_arm_3d.rotation.x = clamp(spring_arm_3d.rotation.x, -PI/3, PI/5)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
spring_arm_3d.spring_length = SpringLenght
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue