1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-21 15:34:17 +00:00

🛠️ Add bobbing to peashooter

This commit is contained in:
Ichicoro 2023-01-08 18:39:37 +01:00
parent 12b5cdd1b9
commit 1fcca314e2
11 changed files with 134 additions and 21 deletions

Binary file not shown.

View file

@ -89,6 +89,7 @@ environment = SubResource("Environment_302o8")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -0.249636, 0.96834, 0, -0.96834, -0.249636, 0, 7.44648, 0)
light_color = Color(1, 0.698039, 0.470588, 1)
[node name="Player" parent="." instance=ExtResource("3_5378m")]
transform = Transform3D(-1, 3.48787e-16, -8.74228e-08, 3.48787e-16, 1, -3.48787e-16, 8.74228e-08, -3.48787e-16, -1, 2.08165e-12, 4.896, 2.08165e-12)

View file

@ -129,6 +129,7 @@ grow_horizontal = 2
grow_vertical = 2
[node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
@ -168,6 +169,7 @@ theme = SubResource("Theme_smyke")
[node name="FPS_Label" type="Label" parent="HUD"]
visible = false
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
@ -180,7 +182,7 @@ horizontal_alignment = 2
script = SubResource("GDScript_iiadi")
[node name="PointsSpawner" type="Control" parent="HUD"]
layout_mode = 3
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
@ -191,6 +193,7 @@ grow_vertical = 2
script = SubResource("GDScript_5d122")
[node name="AmmoLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
@ -213,13 +216,18 @@ copy_mode = 2
metadata/_edit_lock_ = true
[node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"]
modulate = Color(1, 0.596078, 1, 1)
show_behind_parent = true
z_index = 4096
z_as_relative = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
metadata/_edit_lock_ = true
[node name="SubViewport" type="SubViewport" parent="HUD/SubViewportContainer"]
transparent_bg = true
@ -229,14 +237,15 @@ render_target_update_mode = 4
[node name="WeaponCamera" type="Camera3D" parent="HUD/SubViewportContainer/SubViewport" node_paths=PackedStringArray("MainCamera")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.581502, 0)
visible = false
cull_mask = 4
cull_mask = 2
fov = 80.0
near = 0.001
script = SubResource("GDScript_7qy62")
MainCamera = NodePath("../../../../Head/Viewport/CameraViewportContainer/GameViewport/Camera")
[node name="Crosshair" type="ColorRect" parent="HUD"]
material = SubResource("ShaderMaterial_2p6rt")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0

View file

@ -1,4 +1,4 @@
extends Node
extends Node3D
class_name BaseWeapon
enum WeaponSlot {
@ -12,12 +12,13 @@ enum AmmoType {
SINGLE
}
@export_range(0,1) var MOUSE_MOVEMENT_BOB_AMOUNT := 0.5
@export_range(0,0.002) var MOUSE_MOVEMENT_BOB_AMOUNT := 0.002
var player: Player
var weaponSlot: WeaponSlot = WeaponSlot.ONE
var ammoType: AmmoType = AmmoType.NONE
var mouse_movement := Vector2.ZERO
var last_mouse_movement := Vector2.ZERO
var mouse_movements := [Vector2.ZERO] as Array[Vector2]
func on_switch_in():
pass
@ -26,13 +27,26 @@ func on_switch_out():
pass
func bob_weapon(node: Node3D, delta: float):
if len(self.mouse_movements) >= 5:
self.mouse_movements.pop_front()
self.mouse_movements.push_back(Vector2(
self.last_mouse_movement.y * 0.05,
self.last_mouse_movement.x * 0.05
))
var avg_mvmt = self.mouse_movements \
.reduce(func(accum, number): return accum + number) \
/ len(self.mouse_movements) as Vector2
node.position = Vector3.ZERO.lerp(Vector3(
-avg_mvmt.y,
avg_mvmt.x,
0,
self.mouse_movement.x*0.05,
-self.mouse_movement.y*0.05,
), delta / MOUSE_MOVEMENT_BOB_AMOUNT)
), MOUSE_MOVEMENT_BOB_AMOUNT / delta)
self.last_mouse_movement = Vector2.ZERO
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
var vec = event.relative
self.mouse_movement = Vector2(vec.y, vec.x)
self.last_mouse_movement = event.relative

View file

@ -24,6 +24,7 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
super.bob_weapon(self, _delta)
var current_time = Time.get_ticks_msec()
if Input.is_action_just_pressed("fire") and current_time > (last_fired + FIRE_RATE*1000):

View file

@ -1,7 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://cu53ekfgwammu"]
[gd_scene load_steps=4 format=3 uid="uid://cu53ekfgwammu"]
[ext_resource type="Script" path="res://player/onhand/PeaShooter.gd" id="1_bl35a"]
[ext_resource type="PackedScene" uid="uid://bjjjpgtdtub3r" path="res://assets/peashooter/peashooter.gltf" id="2_131r2"]
[ext_resource type="PackedScene" uid="uid://bcl83sr2mgwaf" path="res://player/onhand/peashooter_model.tscn" id="2_ra8vl"]
[ext_resource type="AudioStream" uid="uid://bp07vx515hkr2" path="res://assets/peashooter/peashooter.wav" id="4_uhlty"]
@ -16,11 +15,11 @@ collide_with_areas = true
[node name="peashooter2" parent="." instance=ExtResource("2_ra8vl")]
transform = Transform3D(-0.5, 0, -7.54979e-08, 0, 0.5, 0, 7.54979e-08, 0, -0.5, 0.6, -0.8, 0.5)
[node name="peashooter" parent="." instance=ExtResource("2_131r2")]
transform = Transform3D(-0.5, 0, -7.54979e-08, 0, 0.5, 0, 7.54979e-08, 0, -0.5, 0.6, -0.8, 0.5)
visible = false
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("4_uhlty")
volume_db = -7.517
[node name="model" parent="." instance=ExtResource("2_ra8vl")]
transform = Transform3D(-0.5, 1.74393e-16, 4.37114e-08, 1.74393e-16, 0.5, -1.74393e-16, -4.37114e-08, -1.74393e-16, -0.5, 0.6, -0.8, 0.5)

Binary file not shown.

View file

@ -0,0 +1,28 @@
[remap]
importer="2d_array_texture"
type="CompressedTexture2DArray"
uid="uid://d6tfm0fr3nuk"
path.etc2="res://.godot/imported/peashooter_model.exr-6bb301faafe319f062fc21ef485e69c0.etc2.ctexarray"
path.s3tc="res://.godot/imported/peashooter_model.exr-6bb301faafe319f062fc21ef485e69c0.s3tc.ctexarray"
metadata={
"imported_formats": ["etc2", "s3tc"],
"vram_texture": true
}
[deps]
source_file="res://player/onhand/peashooter_model.exr"
dest_files=["res://.godot/imported/peashooter_model.exr-6bb301faafe319f062fc21ef485e69c0.etc2.ctexarray", "res://.godot/imported/peashooter_model.exr-6bb301faafe319f062fc21ef485e69c0.s3tc.ctexarray"]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/channel_pack=1
mipmaps/generate=false
mipmaps/limit=-1
slices/horizontal=1
slices/vertical=1

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -9,7 +9,7 @@
config_version=5
_global_script_classes=[{
"base": "Node",
"base": "Node3D",
"class": &"BaseWeapon",
"language": &"GDScript",
"path": "res://player/onhand/BaseWeapon.gd"
@ -115,6 +115,8 @@ fire={
[layer_names]
3d_render/layer_1="Default"
3d_render/layer_2="OnHand"
3d_physics/layer_1="Default"
3d_physics/layer_2="Pickups"
3d_physics/layer_3="Player"