Flying Laser Cutters

This commit is contained in:
Jakob Feldmann 2022-07-10 16:44:46 +02:00
parent 193bad8702
commit f75c76e437
12 changed files with 154 additions and 62 deletions

View File

@ -138,7 +138,10 @@ boost_move={
[physics]
common/physics_fps=120
common/physics_jitter_fix=0.3
2d/cell_size=100
common/enable_object_picking=false
[rendering]

View File

@ -9,7 +9,9 @@ onready var init_boost = player_state_machine.init_boost
onready var init_boost_type = player_state_machine.init_boost_type
onready var animation_player = $BlobbySprite/BlobbymationPlayer
# TODO Too much speed through midair boosting
# TODO Walljump of of enemies/object not only walls
# TODO Jumping near walls is buggy
# TODO Falling and then touching walls is too fast
# TODO Couple one time applications of force to delta to keep values constant for different physics fps
# When the Enemy stomp AREA enters the enemy collision area -> stomp
@ -71,7 +73,7 @@ func calculate_grounded_velocity(
if reverse_move:
out_vel.x = PhysicsFunc.two_step_euler(
out_vel.x,
deceleration_force * -1.66 * velocity_direction,
deceleration_force * -3.42 * velocity_direction,
mass,
delta
)
@ -180,8 +182,8 @@ func calculate_jump_velocity(
if !Input.is_action_pressed("jump"):
# TODO This is so good not gonna lie
# Smooth transition from jumping to falling
if velocity.y > _gravity * delta * 10:
linear_velocity.y += _gravity * delta * 10
if velocity.y > _gravity * delta * 20:
linear_velocity.y += _gravity * delta * 20
else:
linear_velocity.y += (
max(abs(linear_velocity.y), _gravity * delta)
@ -204,6 +206,7 @@ func calculate_jump_velocity(
delta
)
air_strafe_charges -= 1
# TODO Suspend in air
return linear_velocity

View File

@ -5,6 +5,9 @@
[ext_resource path="res://src/Actors/Blobby/Blobby.gd" type="Script" id=4]
[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=5]
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 13, 9 )
[sub_resource type="StreamTexture" id=5]
load_path = "res://.import/Blobby.png-42eed5028ccb56a7415a0793b79ec61e.stex"
@ -75,24 +78,32 @@ tracks/0/keys = {
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 13, 9 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 13, 9 )
[node name="Blobby" type="KinematicBody2D" groups=["player"]]
collision_mask = 120
collision/safe_margin = 0.001
script = ExtResource( 4 )
[node name="BlobbySkin" type="Area2D" parent="." groups=["player"]]
process_priority = -1
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="BlobbySkin"]
position = Vector2( 0, -9 )
scale = Vector2( 1.03, 1.04 )
shape = SubResource( 2 )
[node name="BlobbySprite" type="Sprite" parent="."]
position = Vector2( 0, -16 )
texture = SubResource( 5 )
hframes = 3
vframes = 3
frame = 5
frame = 7
__meta__ = {
"_editor_description_": "YXNlcHJpdGVfd2l6YXJkX2NvbmZpZwpwbGF5ZXJ8PUJsb2JieVNwcml0ZS9CbG9iYnltYXRpb25QbGF5ZXIKc291cmNlfD1yZXM6Ly9hc3NldHMvYmxvYmJ5L2Jsb2JieS1zcHJpdGVzaGVldHQuYXNlcHJpdGUKbGF5ZXJ8PUJsb2JieQpvcF9leHB8PUZhbHNlCm9fZm9sZGVyfD0Kb19uYW1lfD0Kb25seV92aXNpYmxlfD1GYWxzZQpvX2V4X3B8PQo="
}
[node name="BlobbymationPlayer" type="AnimationPlayer" parent="BlobbySprite"]
playback_process_mode = 0
anims/falling = SubResource( 6 )
anims/idling = SubResource( 7 )
anims/jumping = SubResource( 8 )
@ -121,14 +132,6 @@ script = ExtResource( 2 )
[node name="ShiftTween" type="Tween" parent="BlobbyCam"]
[node name="BlobbySkin" type="Area2D" parent="." groups=["player"]]
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="BlobbySkin"]
position = Vector2( 0, -9 )
scale = Vector2( 1.03, 1.03 )
shape = SubResource( 2 )
[node name="BlobbyStateMachine" type="Node" parent="."]
script = ExtResource( 3 )
@ -162,14 +165,14 @@ position = Vector2( -13, -4 )
enabled = true
exclude_parent = false
cast_to = Vector2( -1, 0 )
collision_mask = 8
collision_mask = 56
[node name="Left_Wallcast2" type="RayCast2D" parent="WallRaycasts/LeftWallRaycast"]
position = Vector2( -13, 6 )
enabled = true
exclude_parent = false
cast_to = Vector2( -1, 0 )
collision_mask = 8
collision_mask = 56
[node name="RightWallRaycast" type="Node2D" parent="WallRaycasts"]
position = Vector2( 0, -8 )
@ -179,14 +182,14 @@ position = Vector2( 13, -5 )
enabled = true
exclude_parent = false
cast_to = Vector2( 1, 0 )
collision_mask = 8
collision_mask = 56
[node name="Right_Wallcast2" type="RayCast2D" parent="WallRaycasts/RightWallRaycast"]
position = Vector2( 13, 5 )
enabled = true
exclude_parent = false
cast_to = Vector2( 1, 0 )
collision_mask = 8
collision_mask = 56
[connection signal="area_entered" from="BlobbySkin" to="." method="_on_BlobbySkin_area_entered"]
[connection signal="body_entered" from="BlobbySkin" to="." method="_on_BlobbySkin_body_entered"]

View File

@ -98,13 +98,13 @@ collision_mask = 123
[node name="SightCone" type="Node2D" parent="."]
[node name="Sightline1" type="RayCast2D" parent="SightCone"]
rotation = 0.0698132
rotation = 0.0174533
enabled = true
cast_to = Vector2( 0, 100000 )
collision_mask = 121
[node name="Sightline2" type="RayCast2D" parent="SightCone"]
rotation = -0.0698132
rotation = -0.0174533
enabled = true
cast_to = Vector2( 0, 100000 )
collision_mask = 121

View File

@ -8,23 +8,23 @@ var stomp_feedback := 1000.0
var inair_velocity := 21
var wallslide_threshold := 1000
# TODO Map to floor types and move to physics constants
var normal_floor_friction := 0.5
var normal_floor_friction := 1
var max_velocity := {
"walk": 120, "run": 160, "fall": 420, "walljump": 200, "idle": 12000
}
var velocity_jump_boost_ratio := 10
# This is added to the acceleration force initially
var init_acceleration_force := {
"idle_walk": 4181, "idle_run": 5765, "walk_run": 1000
"idle_walk": 4181/2, "idle_run": 5765/2, "walk_run": 1000/2
}
# Oriented around deltas of 0.0166666...s
# newtonmeters is the unit
var acceleration_force := {
"walk": Vector2(2000, 74000),
"idle": Vector2(2000, 74000),
"run": Vector2(2800, 74000),
"walljump": Vector2(36000, 63000),
"air_strafe": Vector2(20000, 100)
"walk": Vector2(1000, 148000),
"idle": Vector2(1000, 148000),
"run": Vector2(1400, 148000),
"walljump": Vector2(72000, 126000),
"air_strafe": Vector2(40000, 2000)
}
# Gravity as m/s^2
var _gravity: float = PhysicsConst.gravity

View File

@ -0,0 +1,57 @@
extends KinematicBody2D
const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
#Array of RayCast2D
onready var trigger_rays = $Triggers.get_children()
onready var tween = $Tween
onready var original_position: Vector2 = self.global_position
onready var local_facing: Vector2 = Vector2.RIGHT
onready var global_facing: Vector2 = local_facing.rotated(transform.get_rotation())
var flyoff_triggered = false
var velocity = 1
var max_velocity = 200
var acceleration_force = 1200
var mass = 10
# TODO Returing Laser cutter has broken collision and infinite impulse
# TODO Friction on the laser and other platforms should be higher
func _ready() -> void:
$Sprite/AnimationPlayer.play("default")
func _physics_process(delta: float) -> void:
if !flyoff_triggered:
for ray in trigger_rays:
if ray.is_colliding():
var collider = ray.get_collider()
if collider.is_in_group("player"):
tween.stop(self)
set("motion/sync_to_physics", false)
flyoff_triggered = true
break
else:
velocity = PhysicsFunc.two_step_euler(
velocity, acceleration_force, mass, delta
)
velocity = clamp(velocity, 0, max_velocity)
var collision = move_and_collide(velocity*global_facing*delta,true)
if collision != null:
if !collision.collider.is_in_group("player"):
_on_collision()
func _on_collision() -> void:
velocity = 1
flyoff_triggered = false
set("motion/sync_to_physics", true)
var distance: Vector2 = self.global_position - original_position
var time_vec = Vector2(abs(distance.x), abs(distance.y)) / (max_velocity / 3)
var time = time_vec.length()
tween.interpolate_property(
self, "position", self.global_position, original_position, time
)
tween.start()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,9 +1,14 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://src/Contraptions/Platform/FlyingLaserCutter.gd" type="Script" id=1]
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 3.30347, 10.9923 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 11.9718, 11.9718 )
extents = Vector2( 11.9396, 11.9718 )
[sub_resource type="StreamTexture" id=1]
[sub_resource type="StreamTexture" id=6]
load_path = "res://.import/FlyingLaserCutter.png-9cf80385a79c58041216f8c2509a5bab.stex"
[sub_resource type="Animation" id=2]
@ -22,21 +27,33 @@ tracks/0/keys = {
"values": [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0 ]
}
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 10.7929, 10 )
[node name="FlyingLaserCutter" type="KinematicBody2D"]
collision_layer = 32
collision_mask = 123
collision/safe_margin = 0.001
script = ExtResource( 1 )
[node name="LaserArea" type="Area2D" parent="." groups=["harmful"]]
process_priority = -1
collision_layer = 32
collision_mask = 3
[node name="PainZone" type="CollisionShape2D" parent="LaserArea" groups=["harmful"]]
process_priority = -1
position = Vector2( 9.88403, 0.0077219 )
shape = SubResource( 4 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -0.0136938, 0 )
shape = SubResource( 3 )
[node name="Tween" type="Tween" parent="."]
playback_process_mode = 0
[node name="Sprite" type="Sprite" parent="."]
texture = SubResource( 1 )
texture = SubResource( 6 )
hframes = 5
vframes = 5
frame = 11
__meta__ = {
"_editor_description_": "YXNlcHJpdGVfd2l6YXJkX2NvbmZpZwpwbGF5ZXJ8PVNwcml0ZS9BbmltYXRpb25QbGF5ZXIKc291cmNlfD1yZXM6Ly9hc3NldHMvY29udHJhcHRpb24vRmx5aW5nTGFzZXJDdXR0ZXIuYXNlcHJpdGUKbGF5ZXJ8PQpvcF9leHB8PUZhbHNlCm9fZm9sZGVyfD0Kb19uYW1lfD0Kb25seV92aXNpYmxlfD1GYWxzZQpvX2V4X3B8PQo="
}
@ -44,14 +61,23 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="Sprite"]
anims/default = SubResource( 2 )
[node name="LaserArea" type="Area2D" parent="." groups=["harmful"]]
collision_layer = 32
collision_mask = 255
[node name="Triggers" type="Node2D" parent="."]
position = Vector2( 0, 0.0077219 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="LaserArea"]
position = Vector2( 1.1396, 0 )
shape = SubResource( 4 )
[node name="RayCast2D" type="RayCast2D" parent="."]
[node name="RayCast2D" type="RayCast2D" parent="Triggers"]
position = Vector2( 3.92072e-12, 8.99337 )
rotation = -1.5708
scale = Vector2( 1, 1000 )
enabled = true
cast_to = Vector2( 0, 1 )
collision_mask = 9
[node name="RayCast2D2" type="RayCast2D" parent="Triggers"]
position = Vector2( 0, -8.95621 )
rotation = -1.5708
scale = Vector2( 1, 1000 )
enabled = true
cast_to = Vector2( 0, 1 )
collision_mask = 9
[connection signal="area_entered" from="LaserArea" to="." method="_on_LaserArea_area_entered"]

View File

@ -27,7 +27,7 @@ tracks/0/keys = {
script = ExtResource( 2 )
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
position = Vector2( 25.7293, 0 )
position = Vector2( 24.4777, 0 )
collision_layer = 8
collision_mask = 0
motion/sync_to_physics = true

View File

@ -34,6 +34,7 @@ points = PoolVector2Array( 23.7224, 24, 0, 24, 0, 0, 24, 0 )
1/z_index = 0
[node name="LevelTemplate" type="Node2D"]
scale = Vector2( 0.998402, 1.0004 )
__meta__ = {
"_edit_horizontal_guides_": [ 464.0 ],
"_edit_vertical_guides_": [ 2880.0 ]
@ -48,7 +49,6 @@ position = Vector2( -259.915, 710.547 )
tile_set = SubResource( 2 )
cell_size = Vector2( 24, 24 )
cell_quadrant_size = 12
cell_custom_transform = Transform2D( 24, 0, 0, 24, 0, 0 )
collision_layer = 8
collision_mask = 0
format = 1
@ -60,12 +60,22 @@ position = Vector2( 1989, 528 )
[node name="Collectibles" type="Node" parent="."]
[node name="Coin" parent="Collectibles" instance=ExtResource( 5 )]
position = Vector2( -65.9265, 721.783 )
position = Vector2( -166.948, 610.671 )
scale = Vector2( 0.15, 0.15 )
[node name="AnimatedSprite" parent="Collectibles/Coin" index="2"]
frame = 57
frame = 104
[node name="FlyingLaserCutter" parent="." instance=ExtResource( 6 )]
position = Vector2( -169.145, 696.547 )
[node name="FlyingLaserCutter3" parent="." instance=ExtResource( 6 )]
position = Vector2( -167.267, 632.742 )
rotation = 1.5708
[node name="FlyingLaserCutter4" parent="." instance=ExtResource( 6 )]
position = Vector2( -296.474, 577.769 )
[node name="FlyingLaserCutter5" parent="." instance=ExtResource( 6 )]
position = Vector2( -14.0224, 527.789 )
rotation = -3.14159
scale = Vector2( 0.996031, 1 )
[editable path="Collectibles/Coin"]

View File

@ -1,11 +1,10 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2]
[ext_resource path="res://src/Contraptions/Platform/Spring.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/Environment/Background.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Actors/Enemies/Machines/Turret.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UserInterface/Buttons/UI.tscn" type="PackedScene" id=7]
[sub_resource type="NavigationPolygon" id=1]
@ -64,14 +63,6 @@ collision_mask = 2147483648
format = 1
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18, 0, 0, 19, 0, 0, 20, 0, 0, 21, 0, 0, 22, 0, 0, 23, 0, 0, 24, 0, 0, 25, 0, 0, 26, 0, 0, 27, 0, 0, 28, 0, 0, 29, 0, 0, 30, 0, 0, 65536, 0, 0, 65566, 0, 0, 131072, 0, 0, 131102, 0, 0, 196608, 0, 0, 196638, 0, 0, 262144, 0, 0, 262174, 0, 0, 327680, 0, 0, 327710, 0, 0, 393216, 0, 0, 393246, 0, 0, 458752, 0, 0, 458782, 0, 0, 524288, 0, 0, 524318, 0, 0, 589824, 0, 0, 589854, 0, 0, 655360, 0, 0, 655390, 0, 0, 720896, 0, 0, 720926, 0, 0, 786432, 0, 0, 786462, 0, 0, 851968, 0, 0, 851998, 0, 0, 917504, 0, 0, 917534, 0, 0, 983040, 0, 0, 983070, 0, 0, 1048576, 0, 0, 1048606, 0, 0, 1114112, 0, 0, 1114142, 0, 0, 1179648, 0, 0, 1179678, 0, 0, 1245184, 0, 0, 1245214, 0, 0, 1310720, 0, 0, 1310750, 0, 0, 1376256, 0, 0, 1376286, 0, 0, 1441792, 0, 0, 1441822, 0, 0, 1507328, 0, 0, 1507358, 0, 0, 1572864, 0, 0, 1572894, 0, 0, 1638400, 0, 0, 1638430, 0, 0, 1703936, 0, 0, 1703966, 0, 0, 1769472, 0, 0, 1769502, 0, 0, 1835008, 0, 0, 1835038, 0, 0, 1900544, 0, 0, 1900574, 0, 0, 1966080, 0, 0, 1966110, 0, 0, 2031616, 0, 0, 2031646, 0, 0, 2097152, 0, 0, 2097182, 0, 0, 2162688, 0, 0, 2162718, 0, 0, 2228224, 0, 0, 2228254, 0, 0, 2293760, 0, 0, 2293790, 0, 0, 2359296, 0, 0, 2359326, 0, 0, 2424832, 0, 0, 2424862, 0, 0, 2490368, 0, 0, 2490398, 0, 0, 2555904, 0, 0, 2555905, 0, 0, 2555906, 0, 0, 2555907, 0, 0, 2555908, 0, 0, 2555909, 0, 0, 2555910, 0, 0, 2555911, 0, 0, 2555912, 0, 0, 2555913, 0, 0, 2555914, 0, 0, 2555915, 0, 0, 2555916, 0, 0, 2555917, 0, 0, 2555918, 0, 0, 2555919, 0, 0, 2555920, 0, 0, 2555921, 0, 0, 2555922, 0, 0, 2555923, 0, 0, 2555924, 0, 0, 2555925, 0, 0, 2555926, 0, 0, 2555927, 0, 0, 2555928, 0, 0, 2555929, 0, 0, 2555930, 0, 0, 2555931, 0, 0, 2555932, 0, 0, 2555933, 0, 0, 2555934, 0, 0 )
[node name="Turret" parent="." instance=ExtResource( 6 )]
position = Vector2( 479, 430 )
scale = Vector2( 0.354, 0.354 )
[node name="Laserpoint" parent="Turret" index="11"]
position = Vector2( -8.71185, 539.311 )
scale = Vector2( 2.08898, 2.08898 )
[node name="Blobby" parent="." instance=ExtResource( 1 )]
position = Vector2( 50.7867, 604.063 )
@ -92,6 +83,5 @@ scale = Vector2( 2.83999, 0.56 )
[node name="KinematicBody2D" parent="Track" index="0"]
position = Vector2( 25.0812, 0 )
[editable path="Turret"]
[editable path="Spring4"]
[editable path="Track"]