Working caterpillar movement

This commit is contained in:
Jakob Feldmann 2022-11-21 21:47:04 +01:00
parent 8a7df91bc1
commit 4ccca8b0ae
6 changed files with 68 additions and 20 deletions

View File

@ -143,6 +143,7 @@ tracks/10/keys = {
[sub_resource type="Animation" id=6]
resource_name = "deathCam"
length = 2.3
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath(".:zoom")
tracks/0/interp = 1
@ -265,8 +266,21 @@ tracks/9/keys = {
"update": 1,
"values": [ false ]
}
tracks/10/type = "value"
tracks/10/path = NodePath("ColorRect:visible")
tracks/10/interp = 1
tracks/10/loop_wrap = true
tracks/10/imported = false
tracks/10/enabled = true
tracks/10/keys = {
"times": PoolRealArray( 1.6 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ true ]
}
[node name="BlobbyCam" type="Camera2D"]
z_index = 3
rotating = true
current = true
zoom = Vector2( 0.75, 0.75 )
@ -278,6 +292,16 @@ drag_margin_bottom = 0.0
editor_draw_screen = false
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
visible = false
margin_left = -320.0
margin_top = -180.0
margin_right = 320.0
margin_bottom = 178.0
grow_horizontal = 2
grow_vertical = 2
color = Color( 0, 0, 0, 1 )
[node name="ShiftTween" type="Tween" parent="."]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]

View File

@ -2,14 +2,17 @@ extends Player
export var score := 100
onready var left_rc = $SlopeRaycastLeft
onready var right_rc = $SlopeRaycastRight
onready var left_src = $SlopeRaycastLeft
onready var right_src = $SlopeRaycastRight
onready var left_wrc = $WallRaycastLeft
onready var right_wrc = $WallRaycastRight
var snap = Vector2.DOWN * 128
var time = 0
var snap = Vector2.DOWN * 24
func _ready() -> void:
set_physics_process(false)
velocity.x = -30
velocity.x = -120
# TODO adapt to groups
@ -20,13 +23,19 @@ func _on_StompDetector_body_entered(body: Node) -> void:
die()
func _physics_process(delta: float) -> void:
if(left_rc.is_colliding() && right_rc.is_colliding()):
var length_vector: Vector2 = right_rc.get_collision_point() - left_rc.get_collision_point()
rotation = length_vector.angle()
# rotation
var movement = max(0,sign(sin(time*15)))
if(left_src.is_colliding() && right_src.is_colliding() && !left_wrc.is_colliding() && !right_wrc.is_colliding()):
pass
elif(left_wrc.is_colliding() || (!right_src.is_colliding() && left_src.is_colliding())):
rotation += delta * 7 * movement
else:
print(rad2deg(rotation))
rotation += sign(velocity.x) * delta * 1.2
move_and_slide_with_snap(velocity.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI)
rotation -= -sign(velocity.x) * delta * 7 * movement
# 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)
func die() -> void:

View File

@ -13,7 +13,7 @@ extents = Vector2( 15, 6.12039 )
extents = Vector2( 15.534, 10.0962 )
[node name="Caterpillar" type="KinematicBody2D" groups=["harmful"]]
scale = Vector2( 0.8, 0.8 )
scale = Vector2( 0.8, 0.5 )
collision_layer = 2
collision_mask = 9
script = ExtResource( 2 )
@ -31,20 +31,32 @@ process_parent = true
physics_process_parent = true
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
position = Vector2( 0, 6.48802 )
position = Vector2( 0, 6 )
scale = Vector2( 5.68128, 5.29182 )
shape = SubResource( 1 )
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
position = Vector2( -11.25, 12.5 )
position = Vector2( -7.5, 12 )
enabled = true
cast_to = Vector2( 0, 13.75 )
cast_to = Vector2( 0, 1 )
collision_mask = 8
[node name="SlopeRaycastRight" type="RayCast2D" parent="."]
position = Vector2( 11.25, 12.5 )
position = Vector2( 7.5, 12 )
enabled = true
cast_to = Vector2( -9.53674e-07, 13.75 )
cast_to = Vector2( 0, 1 )
collision_mask = 8
[node name="WallRaycastLeft" type="RayCast2D" parent="."]
position = Vector2( -15, 12 )
enabled = true
cast_to = Vector2( -2, 0 )
collision_mask = 8
[node name="WallRaycastRight" type="RayCast2D" parent="."]
position = Vector2( 15, 12 )
enabled = true
cast_to = Vector2( 2, 0 )
collision_mask = 8
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
@ -62,7 +74,6 @@ process_priority = -1
collision_mask = 126
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
position = Vector2( -5.68434e-14, 0 )
scale = Vector2( 1.03, 1.04 )
shape = SubResource( 3 )

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@ position = Vector2( -259.915, 710.547 )
position = Vector2( 220, 804 )
[node name="Caterpillar" parent="." instance=ExtResource( 5 )]
position = Vector2( -41, 782 )
position = Vector2( -37, 786 )
[node name="Enemy2" parent="." instance=ExtResource( 6 )]
position = Vector2( 492, 804 )