Try out grappling hooks
This commit is contained in:
parent
f01ea42327
commit
63ef26bab0
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,3 +7,6 @@
|
||||
|
||||
# Project-specific ignores
|
||||
/builds
|
||||
|
||||
# For blender
|
||||
*.blend[0-9]
|
||||
|
BIN
models/grappling_hook.blend
Normal file
BIN
models/grappling_hook.blend
Normal file
Binary file not shown.
51
models/grappling_hook.blend.import
Normal file
51
models/grappling_hook.blend.import
Normal file
@ -0,0 +1,51 @@
|
||||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://8nth3l65bb7r"
|
||||
path="res://.godot/imported/grappling_hook.blend-2e604f48b288f3a507a2e743fac7348f.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://models/grappling_hook.blend"
|
||||
dest_files=["res://.godot/imported/grappling_hook.blend-2e604f48b288f3a507a2e743fac7348f.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={}
|
||||
blender/nodes/visible=0
|
||||
blender/nodes/active_collection_only=false
|
||||
blender/nodes/punctual_lights=true
|
||||
blender/nodes/cameras=true
|
||||
blender/nodes/custom_properties=true
|
||||
blender/nodes/modifiers=1
|
||||
blender/meshes/colors=false
|
||||
blender/meshes/uvs=true
|
||||
blender/meshes/normals=true
|
||||
blender/meshes/tangents=true
|
||||
blender/meshes/skins=2
|
||||
blender/meshes/export_bones_deforming_mesh_only=false
|
||||
blender/materials/unpack_enabled=true
|
||||
blender/materials/export_materials=1
|
||||
blender/animation/limit_playback=true
|
||||
blender/animation/always_sample=true
|
||||
blender/animation/group_tracks=true
|
@ -19,6 +19,8 @@ config/icon="res://misc/icon.svg"
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/stretch/mode="canvas_items"
|
||||
window/stretch/scale=2.0
|
||||
|
||||
[dotnet]
|
||||
|
||||
@ -93,9 +95,14 @@ jump={
|
||||
sprint={
|
||||
"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":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":true,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
shoot_hook={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null)
|
||||
, 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":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
20
scenes/grappling_hook.tscn
Normal file
20
scenes/grappling_hook.tscn
Normal file
@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ddcoq5j1kntji"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://8nth3l65bb7r" path="res://models/grappling_hook.blend" id="1_nljl0"]
|
||||
[ext_resource type="Script" path="res://scripts/GrapplingHook.cs" id="1_yecm5"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rp2xw"]
|
||||
size = Vector3(0.872498, 0.875122, 0.902222)
|
||||
|
||||
[node name="GrapplingHook" type="RigidBody3D"]
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 1
|
||||
script = ExtResource("1_yecm5")
|
||||
|
||||
[node name="grappling_hook" parent="." instance=ExtResource("1_nljl0")]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 0, 0, 1, 0.00187739, -0.0024816, -0.348884)
|
||||
shape = SubResource("BoxShape3D_rp2xw")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnCollisionEntered"]
|
@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://wjbuh7jk50nm"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://wjbuh7jk50nm"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Player.cs" id="1_aff2a"]
|
||||
[ext_resource type="PackedScene" uid="uid://ddcoq5j1kntji" path="res://scenes/grappling_hook.tscn" id="2_s04ug"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_rgktv"]
|
||||
height = 1.9
|
||||
@ -9,6 +10,7 @@ radius = 0.3
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("Eye")]
|
||||
script = ExtResource("1_aff2a")
|
||||
Eye = NodePath("PlayerEyeCamera")
|
||||
GrapplingHookInstantiable = ExtResource("2_s04ug")
|
||||
|
||||
[node name="PlayerEyeCamera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7, 0)
|
||||
@ -16,3 +18,20 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7, 0)
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.95, 0)
|
||||
shape = SubResource("CylinderShape3D_rgktv")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(16, 2)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="ColorRect2" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(2, 16)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
|
9
scripts/GrapplingHook.cs
Normal file
9
scripts/GrapplingHook.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class GrapplingHook : RigidBody3D {
|
||||
public void OnCollisionEntered(Node node) {
|
||||
Freeze = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class PauseMenu : Control {
|
||||
private Vector2 SavedMousePosition = Vector2.Zero;
|
||||
private bool Opened = false;
|
||||
|
||||
public override void _Ready() {
|
||||
Close();
|
||||
@ -10,8 +10,12 @@ namespace Gmtk24 {
|
||||
|
||||
public override void _Input(InputEvent @event) {
|
||||
if (@event is InputEventKey keyEvent) {
|
||||
if (keyEvent.Keycode == Key.Escape) {
|
||||
Open();
|
||||
if (keyEvent.Pressed && keyEvent.Keycode == Key.Escape) {
|
||||
if (Opened) {
|
||||
Close();
|
||||
} else {
|
||||
Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -19,12 +23,13 @@ namespace Gmtk24 {
|
||||
public void Open() {
|
||||
Visible = true;
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
SavedMousePosition = GetLocalMousePosition();
|
||||
Opened = true;
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
Visible = false;
|
||||
Opened = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,20 +12,44 @@ namespace Gmtk24 {
|
||||
public float JumpBufferLengthSeconds = 0.2f;
|
||||
[Export]
|
||||
public Node3D Eye;
|
||||
[ExportCategory("Grappling hook stuff")]
|
||||
[Export]
|
||||
public PackedScene GrapplingHookInstantiable;
|
||||
[Export]
|
||||
public float GrapplingHookInitialDistance = 1;
|
||||
|
||||
private float CurrentYaw = 0;
|
||||
private float CurrentPitch = 0;
|
||||
private float JumpBufferTime = 0;
|
||||
private RigidBody3D SentHook;
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event) {
|
||||
if (@event is InputEventMouseMotion ev && Input.MouseMode == Input.MouseModeEnum.Captured) {
|
||||
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured) {
|
||||
var cameraSensitivityX = 2f; // FIXME: use camera sensitivity and invert settings
|
||||
var cameraSensitivityY = 2f; // FIXME: use camera sensitivity and invert settings
|
||||
var mouseMultiplier = 0.0003f;
|
||||
CurrentYaw -= ev.Relative.X * mouseMultiplier * cameraSensitivityX;
|
||||
CurrentPitch -= ev.Relative.Y * mouseMultiplier * cameraSensitivityY;
|
||||
CurrentYaw -= mouseMotion.ScreenRelative.X * mouseMultiplier * cameraSensitivityX;
|
||||
CurrentPitch -= mouseMotion.ScreenRelative.Y * mouseMultiplier * cameraSensitivityY;
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("jump")) {
|
||||
JumpBufferTime = JumpBufferLengthSeconds;
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("shoot_hook")) {
|
||||
if (IsInstanceValid(SentHook)) {
|
||||
GlobalPosition = SentHook.GlobalPosition;
|
||||
SentHook.QueueFree();
|
||||
return;
|
||||
}
|
||||
SentHook = GrapplingHookInstantiable.Instantiate<RigidBody3D>();
|
||||
AddSibling(SentHook);
|
||||
var direction = Eye.GlobalBasis * Vector3.Forward;
|
||||
SentHook.GlobalPosition = Eye.GlobalPosition + direction * GrapplingHookInitialDistance;
|
||||
SentHook.LookAt(SentHook.GlobalPosition + direction, Vector3.Up);
|
||||
SentHook.ApplyCentralImpulse(direction * 50f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
@ -43,9 +67,6 @@ namespace Gmtk24 {
|
||||
if (JumpBufferTime > 0) {
|
||||
JumpBufferTime -= (float)delta;
|
||||
}
|
||||
if (Input.IsActionJustPressed("jump")) {
|
||||
JumpBufferTime = JumpBufferLengthSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
@ -54,7 +75,8 @@ namespace Gmtk24 {
|
||||
Input.GetActionStrength("move_backward") - Input.GetActionStrength("move_forward")
|
||||
);
|
||||
Vector3 move = Eye.Basis * moveInput;
|
||||
move = move.Normalized() * Mathf.Min(1, move.Length()) * MovementSpeed;
|
||||
move.Y = 0;
|
||||
move = move.Normalized() * Mathf.Min(1, moveInput.Length()) * MovementSpeed;
|
||||
if (Input.IsActionPressed("sprint")) {
|
||||
move *= SprintMultiplier;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user