commit
This commit is contained in:
parent
65b6e177c9
commit
fbc909fe22
36
character.gd
36
character.gd
@ -7,14 +7,16 @@ const JUMP_VELOCITY = 4.5
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@onready var cam_pointer = $camPointer
|
||||
@onready var player = $Player
|
||||
@onready var persone = $Persone
|
||||
|
||||
var direction := Vector3(0, 0, -1)
|
||||
var lookDirection := Vector3(0, 0, -1)
|
||||
|
||||
func _ready():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
player.animation("idle")
|
||||
persone.animation("idle")
|
||||
|
||||
func _physics_process(delta: float):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
@ -28,20 +30,26 @@ func _physics_process(delta: float):
|
||||
#
|
||||
#input_dir = cam_pointer
|
||||
|
||||
var direction := Vector3(0, 0, cam_pointer.rotation.y).normalized()
|
||||
print(direction)
|
||||
var dir: Vector3
|
||||
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
direction = (transform.basis * direction)
|
||||
if Input.is_action_pressed("up"):
|
||||
dir = (transform.basis * direction)
|
||||
else:
|
||||
direction *= 0
|
||||
dir = Vector3()
|
||||
|
||||
if direction:
|
||||
player.animation("walk")
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
if dir:
|
||||
var angle = direction.signed_angle_to(lookDirection, Vector3.DOWN)
|
||||
|
||||
var q = lerp(persone.rotation.y, persone.rotation.y + angle, 1)
|
||||
persone.rotation.y = q
|
||||
|
||||
lookDirection = direction.normalized()
|
||||
|
||||
persone.animation("walk")
|
||||
velocity.x = dir.x * SPEED
|
||||
velocity.z = dir.z * SPEED
|
||||
else:
|
||||
player.animation("idle")
|
||||
persone.animation("idle")
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
@ -51,3 +59,5 @@ func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
cam_pointer.rotation.y -= event.relative.x * .01
|
||||
cam_pointer.rotation.x -= event.relative.y * .01
|
||||
|
||||
direction = direction.rotated(Vector3.DOWN, event.relative.x * .01)
|
||||
|
@ -14,5 +14,5 @@ script = ExtResource("1_ex0f5")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.02691, 0)
|
||||
shape = SubResource("CapsuleShape3D_rjvcb")
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_h0ic1")]
|
||||
[node name="Persone" parent="." instance=ExtResource("1_h0ic1")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
@ -12,4 +12,4 @@ func _process(delta):
|
||||
pass
|
||||
|
||||
func animation(animation: String):
|
||||
animation_player.play(animation)
|
||||
animation_player.play(animation, .100)
|
||||
|
@ -14,3 +14,26 @@ config/name="Game"
|
||||
run/main_scene="res://world.tscn"
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[input]
|
||||
|
||||
up={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
back={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
14
world.tscn
14
world.tscn
@ -1,10 +1,19 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://d4gm4p4h8i45m"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://d4gm4p4h8i45m"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ctdna511sp1wv" path="res://character.tscn" id="1_vfan6"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_c68hd"]
|
||||
size = Vector3(13, 1, 17)
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_m5ll3"]
|
||||
|
||||
[sub_resource type="Sky" id="Sky_5gabu"]
|
||||
sky_material = SubResource("ProceduralSkyMaterial_m5ll3")
|
||||
|
||||
[sub_resource type="Environment" id="Environment_ffmly"]
|
||||
background_mode = 2
|
||||
sky = SubResource("Sky_5gabu")
|
||||
|
||||
[node name="Node3D" type="Node3D"]
|
||||
|
||||
[node name="CharacterBody3D" parent="." instance=ExtResource("1_vfan6")]
|
||||
@ -27,3 +36,6 @@ shape = SubResource("BoxShape3D_c68hd")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.870321, 0.054256, -0.489487, 0.492484, -0.0958815, 0.865024, 0, -0.993913, -0.110168, -5.29032, 3.36282, 0)
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_ffmly")
|
||||
|
Loading…
x
Reference in New Issue
Block a user