Add simple controls
This commit is contained in:
parent
93809e7fd6
commit
bbb6856185
@ -1,6 +1,6 @@
|
||||
[gd_resource type="Map" format=3 uid="uid://b4rw48yjf7q3q"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://lahirbqfppvw" path="res://scenes/main.tscn" id="1_k5804"]
|
||||
[ext_resource type="PackedScene" uid="uid://7iooamjot1tg" path="res://scenes/map0.tscn" id="1_k5804"]
|
||||
|
||||
[resource]
|
||||
name = "Default Map"
|
||||
|
||||
@ -43,6 +43,26 @@ toggle_cli={
|
||||
, 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":4194343,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left={
|
||||
"deadzone": 0.2,
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.2,
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
forward={
|
||||
"deadzone": 0.2,
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
backward={
|
||||
"deadzone": 0.2,
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
|
||||
@ -2,7 +2,16 @@
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ct70bpbca8one" path="res://scenes/player.tscn" id="1_y4ph1"]
|
||||
|
||||
[sub_resource type="ImageTexture" id="ImageTexture_3vyb7"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_u8vuu"]
|
||||
albedo_texture = SubResource("ImageTexture_3vyb7")
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_1cgct"]
|
||||
size = Vector2(100, 100)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1cgct"]
|
||||
size = Vector3(100, 0.01, 100)
|
||||
|
||||
[node name="map_0" type="Node3D" unique_id=1710628675]
|
||||
|
||||
@ -14,12 +23,18 @@ offset_bottom = 649.0
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="terrain" type="MeshInstance3D" parent="." unique_id=1474127252]
|
||||
transform = Transform3D(100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0)
|
||||
material_override = SubResource("StandardMaterial3D_u8vuu")
|
||||
mesh = SubResource("PlaneMesh_1cgct")
|
||||
|
||||
[node name="static_body_3d" type="StaticBody3D" parent="terrain" unique_id=203785193]
|
||||
|
||||
[node name="collision_shape_3d" type="CollisionShape3D" parent="terrain/static_body_3d" unique_id=1466526153]
|
||||
shape = SubResource("BoxShape3D_1cgct")
|
||||
|
||||
[node name="player" parent="." unique_id=1910472598 instance=ExtResource("1_y4ph1")]
|
||||
look_sensitivity = 2.0
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.002088, 0)
|
||||
look_sensitivity = 1.5
|
||||
move_speed = 10.0
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.4560637, 0)
|
||||
|
||||
[node name="directional_light_3d" type="DirectionalLight3D" parent="." unique_id=793524416]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.7274598, 0.6861503, 0, -0.6861503, 0.7274598, -5.1267624, 3.3997262, 3.715582)
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
[node name="player" type="Player" unique_id=1910472598 node_paths=PackedStringArray("camera")]
|
||||
look_sensitivity = 1.0
|
||||
camera = NodePath("camera_3d")
|
||||
move_speed = 5.0
|
||||
|
||||
[node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=700336478]
|
||||
mesh = SubResource("CapsuleMesh_1cgct")
|
||||
|
||||
@ -17,6 +17,10 @@ pub struct Player {
|
||||
look_sensitivity: f32,
|
||||
#[export]
|
||||
camera: Option<Gd<Camera3D>>,
|
||||
#[export]
|
||||
move_speed: f32,
|
||||
|
||||
y_speed: f32,
|
||||
|
||||
locked: bool,
|
||||
|
||||
@ -42,7 +46,32 @@ impl ICharacterBody3D for Player {
|
||||
});
|
||||
}
|
||||
|
||||
fn process(&mut self, delta: f64) {}
|
||||
fn process(&mut self, delta: f64) {
|
||||
self.y_speed -= 9.8 * delta as f32;
|
||||
if self.base().is_on_floor() && self.y_speed < 0. {
|
||||
self.y_speed = 0.;
|
||||
}
|
||||
|
||||
let input_direction = if self.locked {
|
||||
let input = Input::singleton();
|
||||
Vector3::RIGHT * input.is_action_pressed("right") as u32 as f32
|
||||
- Vector3::RIGHT * input.is_action_pressed("left") as u32 as f32
|
||||
+ Vector3::FORWARD * input.is_action_pressed("forward") as u32 as f32
|
||||
- Vector3::FORWARD * input.is_action_pressed("backward") as u32 as f32
|
||||
} else {
|
||||
Vector3::ZERO
|
||||
};
|
||||
|
||||
let speed = Vector3::UP * self.y_speed
|
||||
+ input_direction
|
||||
.try_normalized()
|
||||
.unwrap_or_default()
|
||||
.rotated(Vector3::UP, self.base().get_rotation().y)
|
||||
* self.move_speed;
|
||||
|
||||
self.base_mut().set_velocity(speed);
|
||||
self.base_mut().move_and_slide();
|
||||
}
|
||||
|
||||
fn input(&mut self, event: Gd<InputEvent>) {
|
||||
if self.locked {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user