[wip] Add player physics
This commit is contained in:
parent
d76ab55a3d
commit
8820638e3e
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=110 format=4 uid="uid://8po7ftboqq4k"]
|
||||
[gd_scene load_steps=113 format=4 uid="uid://8po7ftboqq4k"]
|
||||
|
||||
[ext_resource type="CameraAttributesPhysical" uid="uid://cxyj2tvfksjl6" path="res://maps/hazy_env_camera_attrs.tres" id="1_r2j1d"]
|
||||
[ext_resource type="LightmapGIData" uid="uid://bp05p4yab2ukx" path="res://maps/demo.lmbake" id="2_2ehlo"]
|
||||
@ -9,6 +9,7 @@
|
||||
[ext_resource type="Material" uid="uid://bpikku6t3gxi5" path="res://textures/white.tres" id="7_70h1h"]
|
||||
[ext_resource type="Material" uid="uid://dgf570wtqn17j" path="res://textures/steel_fence.tres" id="8_dovc4"]
|
||||
[ext_resource type="PackedScene" uid="uid://b61birqrnbee3" path="res://prefabs/building_block_creator.tscn" id="9_w4r35"]
|
||||
[ext_resource type="Script" path="res://scripts/Player.cs" id="10_87t4r"]
|
||||
|
||||
[sub_resource type="ArrayMesh" id="ArrayMesh_kaiip"]
|
||||
lightmap_size_hint = Vector2i(1030, 566)
|
||||
@ -648,6 +649,13 @@ points = PackedVector3Array(-15.2154, 16, 3.21429, 0.784632, -16, -12.7857, 2.78
|
||||
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_i1n6v"]
|
||||
points = PackedVector3Array(-3.21348, 16, 13.2143, 12.7865, -16, -2.78572, 15.7846, -16, -2.78571, -0.21537, 16, 13.2143, -3.21348, 16, 15.2143, 12.7865, -16, -0.785713, 15.7846, -16, -0.785711, -0.215368, 16, 15.2143)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_pxxc6"]
|
||||
radius = 0.3
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_cnaby"]
|
||||
height = 0.6
|
||||
radius = 0.3
|
||||
|
||||
[node name="Demo" type="Node3D"]
|
||||
|
||||
[node name="LightmapGI" type="LightmapGI" parent="."]
|
||||
@ -1018,10 +1026,8 @@ shape = SubResource("ConvexPolygonShape3D_ldbum")
|
||||
[node name="entity_17_brush_6_collision_shape" type="CollisionShape3D" parent="FuncGodotMap/entity_17_func_buildingblock"]
|
||||
shape = SubResource("ConvexPolygonShape3D_i1n6v")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(0.975917, 0.0634147, -0.208722, 0, 0.956814, 0.290702, 0.218143, -0.283701, 0.93377, -16.896, 2.82889, 36.323)
|
||||
|
||||
[node name="BuildingBlockCreator" parent="." node_paths=PackedStringArray("TrenchbroomMap") instance=ExtResource("9_w4r35")]
|
||||
transform = Transform3D(0.10442, 0, 0, 0, 0.10442, 0, 0, 0, 0.10442, 0, 2, -3)
|
||||
TrenchbroomMap = NodePath("../FuncGodotMap")
|
||||
|
||||
[node name="ReflectionProbes" type="Node3D" parent="."]
|
||||
@ -1053,3 +1059,21 @@ size = Vector3(87.9724, 96.1174, 91.8458)
|
||||
[node name="ReflectionProbe2" type="ReflectionProbe" parent="ReflectionProbes"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0415039, 58.3319, 0.0198975)
|
||||
size = Vector3(43.3174, 26.5295, 43.4319)
|
||||
|
||||
[node name="Player" type="RigidBody3D" parent="." node_paths=PackedStringArray("GroundCast")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.05117, 0)
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_z = true
|
||||
can_sleep = false
|
||||
script = ExtResource("10_87t4r")
|
||||
GroundCast = NodePath("GroundCast")
|
||||
UprightingSpeed = 10.0
|
||||
|
||||
[node name="CoreBody" type="CollisionShape3D" parent="Player"]
|
||||
shape = SubResource("SphereShape3D_pxxc6")
|
||||
|
||||
[node name="PlayerEyeCamera" type="Camera3D" parent="Player"]
|
||||
|
||||
[node name="GroundCast" type="ShapeCast3D" parent="Player"]
|
||||
shape = SubResource("CylinderShape3D_cnaby")
|
||||
target_position = Vector3(0, -1.3, 0)
|
||||
|
@ -29,6 +29,63 @@ texture={
|
||||
"mipmaps/generate": true
|
||||
}
|
||||
|
||||
[input]
|
||||
|
||||
move_forward={
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
, 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":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_backward={
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
, 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":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
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":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, 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)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"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":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, 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)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
look_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
look_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
look_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
look_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"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,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[internationalization]
|
||||
|
||||
rendering/positional_shadow/atlas_quadrant_0_subdiv=2
|
||||
|
48
scripts/Player.cs
Normal file
48
scripts/Player.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Player : RigidBody3D {
|
||||
[Export]
|
||||
public ShapeCast3D GroundCast;
|
||||
[Export]
|
||||
public float UprightingSpeed = 1;
|
||||
[Export]
|
||||
public float MovementSpeed = 7;
|
||||
[Export]
|
||||
public bool PhysicsControlled = false;
|
||||
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
if (PhysicsControlled) {
|
||||
CustomIntegrator = false;
|
||||
} else {
|
||||
// Disable physics movement
|
||||
CustomIntegrator = true;
|
||||
LinearVelocity = Vector3.Zero;
|
||||
AngularVelocity = Vector3.Zero;
|
||||
|
||||
Vector3 pos = Position;
|
||||
|
||||
// Move up enough to no longer have the groundcast hit
|
||||
if (GroundCast.IsColliding()) {
|
||||
float distanceToUpright = 0;
|
||||
for (int i = 0; i < GroundCast.GetCollisionCount(); i++) {
|
||||
distanceToUpright = Mathf.Max(distanceToUpright, (GroundCast.GetCollisionPoint(i) - GroundCast.TargetPosition).Length());
|
||||
}
|
||||
float step = Mathf.Min(distanceToUpright, UprightingSpeed * (float)delta);
|
||||
pos.Y += step;
|
||||
} else {
|
||||
pos.Y += GetGravity().Y * (float)delta;
|
||||
}
|
||||
|
||||
// On-ground movement
|
||||
float zMoveInput = Input.GetActionStrength("move_backward") - Input.GetActionStrength("move_forward");
|
||||
float xMoveInput = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");
|
||||
Vector3 moveInput = new Vector3(xMoveInput, 0, zMoveInput) * Basis;
|
||||
moveInput = moveInput.Normalized() * Mathf.Min(1, moveInput.Length());
|
||||
pos += moveInput * MovementSpeed * (float)delta;
|
||||
|
||||
Position = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user