Add jumping

main
copygirl 1 year ago
parent c21e4db3ea
commit ed08dce086
  1. 2
      objects/crate.tscn
  2. 1
      player/AnimationController.cs
  3. 15
      player/MovementController.cs
  4. 5
      project.godot
  5. 16
      scenes/warehouse.tscn

@ -5,12 +5,14 @@
[ext_resource type="PackedScene" uid="uid://b2f0teloaalm7" path="res://assets/models/crate.gltf" id="3_tncd6"]
[sub_resource type="BoxShape3D" id="BoxShape3D_to3fn"]
size = Vector3(1, 0.75, 1)
[node name="Crate" type="StaticBody3D"]
script = ExtResource("1_mtvxk")
Palette = ExtResource("2_n415g")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.125, 0)
shape = SubResource("BoxShape3D_to3fn")
[node name="blockbench_export" parent="." instance=ExtResource("3_tncd6")]

@ -145,7 +145,6 @@ public partial class AnimationController : Node3D
} else
_bodyYaw -= _bodyYaw * (float)delta * 2;
// FIXME: Something is causing `_bodyYaw` to jitter when a player is pushed against an object.
_bones["Root" ].GlobalRotate(Vector3.Up, _bodyYaw * (YawFactorLowerBody + YawFactorUpperBody + YawFactorNeck));
_bones["LowerBody"].GlobalRotate(Vector3.Up, -_bodyYaw * YawFactorLowerBody);
_bones["UpperBody"].GlobalRotate(Vector3.Up, -_bodyYaw * YawFactorUpperBody);

@ -35,14 +35,20 @@ public partial class MovementController : Node
public override void _UnhandledInput(InputEvent @event)
{
if(!_player.IsLocal) return;
// TODO: Sprinting.
// TODO: Jumping.
if (@event.IsActionPressed("move_jump")) {
TimeSinceJumpPressed = 0.0f;
GetViewport().SetInputAsHandled();
}
}
public override void _PhysicsProcess(double delta)
{
var velocity = _player.Velocity;
// velocity.Y -= Gravity * (float)delta; // TODO: Gravity.
velocity.Y -= Gravity * (float)delta;
// Get the (normalized) movement vector from the current input.
InputVector = _player.IsLocal
@ -54,7 +60,7 @@ public partial class MovementController : Node
var target = basis * new Vector3(InputVector.X, 0, InputVector.Y) * MaxSpeed;
var isMoving = target.Dot(horVelocity) > 0.0f;
var isOnFloor = true; // _player.IsOnFloor();
var isOnFloor = _player.IsOnFloor();
var accel = isMoving ? Acceleration
: isOnFloor ? FrictionFloor
: FrictionAir;
@ -74,7 +80,8 @@ public partial class MovementController : Node
if ((TimeSinceJumpPressed <= JumpEarlyTime) && (TimeSinceOnFloor <= JumpCoyoteTime)) {
TimeSinceJumpPressed = TimeSinceOnFloor = float.PositiveInfinity;
velocity.Y = JumpVelocity;
}
} else
TimeSinceJumpPressed += (float)delta;
_player.Velocity = velocity;
_player.MoveAndSlide();

@ -63,6 +63,11 @@ move_strafe_right={
"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_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)
]
}
interact_pickup={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(131, 20),"global_position":Vector2(135, 61),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://bwfuet1irfi17"]
[gd_scene load_steps=14 format=3 uid="uid://bwfuet1irfi17"]
[ext_resource type="PackedScene" uid="uid://dmd7w2r8s0x6y" path="res://player/player.tscn" id="1_cxvln"]
[ext_resource type="Script" path="res://objects/Grid.cs" id="2_gstd0"]
@ -24,6 +24,11 @@ size = Vector3(2, 0.1, 1)
[sub_resource type="BoxMesh" id="BoxMesh_efbik"]
size = Vector3(0.1, 0.9, 0.1)
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_5erfn"]
[sub_resource type="PlaneMesh" id="PlaneMesh_tg4vq"]
size = Vector2(10, 10)
[node name="Warehouse" type="Node3D"]
[node name="Sun" type="DirectionalLight3D" parent="."]
@ -124,3 +129,12 @@ skeleton = NodePath("../MeshInstance3D")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.9, 0.45, -0.4)
mesh = SubResource("BoxMesh_efbik")
skeleton = NodePath("../MeshInstance3D")
[node name="Floor" type="StaticBody3D" parent="."]
collision_mask = 0
[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"]
shape = SubResource("WorldBoundaryShape3D_5erfn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor"]
mesh = SubResource("PlaneMesh_tg4vq")

Loading…
Cancel
Save