fix: Adjusted the stomping mechanic

Instead of checking the height of the entry of blobbys hitbox
in the enemy stomping area, the success of the stomp now depends
on the angle of entry into the stomping area.
This commit is contained in:
Jakob Feldmann 2023-04-16 23:32:28 +02:00
parent 650b71e289
commit 73b6f64f8e
9 changed files with 45 additions and 38 deletions

View File

@ -61,7 +61,6 @@ GlobalState="*res://src/Autoload/GlobalState.tscn"
[debug]
settings/fps/force_fps=60
settings/stdout/print_fps=true
[display]

View File

@ -140,9 +140,6 @@ func _get_transition(delta):
# + String(round(parent.velocity.y / 10))
)
var new_state
print(was_coyote_hanging)
print("timer")
print($CoyoteTimer.wait_time)
if !parent.is_on_floor():
if parent.velocity.y < -1:
was_coyote_hanging = false

View File

@ -24,4 +24,4 @@ func _physics_process(delta: float) -> void:
# velocity
var v = Vector2(velocity.x * movement, 0)
time += delta
move_and_slide_with_snap(v.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI)
move_and_slide_with_snap(v.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI, false)

View File

@ -4,16 +4,16 @@
[ext_resource path="res://src/Actors/Enemies/Beings/Caterpillar.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 2.72463, 1.17848 )
extents = Vector2( 2.64025, 1.15615 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 18.75, 6.38067 )
extents = Vector2( 15, 6 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 14.563, 9.38461 )
extents = Vector2( 15, 12 )
[node name="Caterpillar" type="KinematicBody2D" groups=["harmful"]]
scale = Vector2( 0.8, 0.5 )
scale = Vector2( 0.747749, 0.572926 )
collision_layer = 2
collision_mask = 9
script = ExtResource( 2 )
@ -30,8 +30,8 @@ rect = Rect2( -89, -10, 2, 20 )
process_parent = true
physics_process_parent = true
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
position = Vector2( 0, 6 )
[node name="EnemyBody" type="CollisionShape2D" parent="."]
position = Vector2( 6.70552e-07, 6.11815 )
scale = Vector2( 5.68128, 5.29182 )
shape = SubResource( 1 )
@ -61,21 +61,23 @@ collision_mask = 8
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
modulate = Color( 0, 0.0392157, 1, 1 )
light_mask = 0
position = Vector2( 0, -6.44095 )
collision_layer = 2
input_pickable = false
monitorable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"]
position = Vector2( 0, 0.0602803 )
position = Vector2( 0, 0.440949 )
shape = SubResource( 2 )
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
process_priority = -1
collision_layer = 2
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
position = Vector2( 0, 3.76 )
position = Vector2( -5.54991e-05, 0 )
scale = Vector2( 1.03, 1.04 )
shape = SubResource( 3 )

View File

@ -2,17 +2,22 @@ extends Actor
class_name Enemy
func _on_StompDetector_body_entered(body: Node) -> void:
if body.global_position.y > get_node("StompDetector").global_position.y:
if !body.is_in_group("player"):
return
if body.is_in_group("player"):
signalManager.emit_signal("got_stomped")
remove_from_group("harmful")
$StompDetector.remove_from_group("weakpoint")
get_node("EnemyBody").disabled = true
die()
var incoming_vel_vector: Vector2 = body.velocity.normalized()
print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(40):
print("too shallow entry")
return
signalManager.emit_signal("got_stomped")
remove_from_group("harmful")
$StompDetector.remove_from_group("weakpoint")
get_node("EnemyBody").disabled = true
die()
func die() -> void:
queue_free()
# TODO make batterr
levelState.kills += 1
func _on_EnemySkin_area_entered(area:Area2D) -> void:

View File

@ -87,7 +87,7 @@ func hunting() -> Vector2:
func detect_player() -> void:
var player
if(players.empty()):
print("no player found")
# print("no player found")
return
player = players[0]
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
@ -98,7 +98,7 @@ func detect_player() -> void:
if(abs(ray_angle_to_facing) < PI/2-deg2rad(blindspot_angle) && collider != null && collider.is_in_group("player")):
target_lost_timer.stop()
target = collider
print("target found")
# print("target found")
elif(target != null && target_lost_timer.is_stopped()):
target_lost_timer.start(loose_target_seconds)
@ -147,7 +147,7 @@ func check_feeler(v: Vector2, _offset = Vector2(0,0)) -> Object:
return feeler_raycast.get_collider()
func lose_target() -> void:
print("flyer target lost")
# print("flyer target lost")
target = null
func update_navigation() -> void:

View File

@ -69,15 +69,18 @@ func bind_to_anchor(anchor_node: Node2D, radius: float ) -> void:
func _on_StompDetector_body_entered(body: Node) -> void:
if body.global_position.y - 1 > get_node("StompDetector").global_position.y:
if !body.is_in_group("player"):
return
if body.is_in_group("player") && !is_hurt:
remove_from_group("harmful")
$StompDetector.remove_from_group("weakpoint")
signalManager.emit_signal("got_stomped")
is_hurt = true
$HurtTimer.start()
$FrogSprite.material = invincible_shader
var incoming_vel_vector: Vector2 = body.velocity.normalized()
print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(50):
print("too shallow entry")
return
signalManager.emit_signal("got_stomped")
remove_from_group("harmful")
$StompDetector.remove_from_group("weakpoint")
get_node("EnemyBody").disabled = true
die()
@ -217,7 +220,7 @@ func detect_food() -> void:
func detect_player() -> void:
var player
if(players.empty()):
print("no player found")
# print("no player found")
return
player = players[0]
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
@ -239,7 +242,7 @@ func sleeping() -> Vector2:
func loose_target() -> void:
print("frog target lost")
# print("frog target lost")
target = null
food_target = null
@ -307,7 +310,7 @@ func consider_jump_headspace(v: Vector2) -> Vector2:
if(height_collider != null):
var collision_point = feeler_raycast.get_collision_point()
var target_height = collision_point.y - (feeler_raycast.global_position.y - 23)
print(feeler_raycast.global_position)
# print(feeler_raycast.global_position)
var new_angle = angle * (0.75 if target_height > -26 else 0.95)
var new_distance = default_jump_distance * (0.66 if target_height > -26 else 0.75)
v = velocity_for_jump_distance(new_distance, abs(new_angle))
@ -496,4 +499,5 @@ func get_facing_direction() -> float:
func _on_HurtTimer_timeout() -> void:
is_hurt = false
add_to_group("harmful")
$FrogSprite.material = null

View File

@ -36,10 +36,10 @@ unique_name_in_owner = true
drag_margin_bottom = 0.3
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 5
frame = 10
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 5
frame = 10
[node name="Blobby" parent="." instance=ExtResource( 8 )]
unique_name_in_owner = true

View File

@ -44,10 +44,10 @@ unique_name_in_owner = true
drag_margin_bottom = 0.3
[node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"]
frame = 1
frame = 11
[node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"]
frame = 1
frame = 11
[node name="Blobby" parent="." instance=ExtResource( 9 )]
unique_name_in_owner = true