Bound Frog behaviour update
The frog can now aquire a target. It jumps more frequently until it loses sight for some period of time.
This commit is contained in:
parent
db04c9d3d5
commit
f4889b22a8
@ -1,8 +1,12 @@
|
|||||||
extends Player
|
extends Player
|
||||||
const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
|
const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
|
||||||
|
|
||||||
|
onready var players = get_tree().get_nodes_in_group("player")
|
||||||
|
|
||||||
|
onready var vision_raycast: RayCast2D = $VisionRayCast
|
||||||
onready var orientation: RayCast2D = $Orientation
|
onready var orientation: RayCast2D = $Orientation
|
||||||
onready var jump_timer: Timer
|
onready var jump_timer: Timer
|
||||||
|
onready var target_lost_timer: Timer
|
||||||
|
|
||||||
export var score := 100
|
export var score := 100
|
||||||
|
|
||||||
@ -10,6 +14,8 @@ var movement_radius: float
|
|||||||
var anchor: Node2D
|
var anchor: Node2D
|
||||||
var is_bound := false
|
var is_bound := false
|
||||||
|
|
||||||
|
var target: Object = null
|
||||||
|
|
||||||
var start_x := 0.0
|
var start_x := 0.0
|
||||||
var in_air := false
|
var in_air := false
|
||||||
var is_hurt := false
|
var is_hurt := false
|
||||||
@ -23,7 +29,10 @@ func _ready():
|
|||||||
jump_timer = Timer.new()
|
jump_timer = Timer.new()
|
||||||
jump_timer.set_one_shot(true)
|
jump_timer.set_one_shot(true)
|
||||||
jump_timer.connect("timeout", self, "jump")
|
jump_timer.connect("timeout", self, "jump")
|
||||||
|
target_lost_timer = Timer.new()
|
||||||
|
target_lost_timer.connect("timeout", self, "lose_target")
|
||||||
add_child(jump_timer)
|
add_child(jump_timer)
|
||||||
|
add_child(target_lost_timer)
|
||||||
|
|
||||||
|
|
||||||
func bind_to_anchor(anchor_node: Node2D, radius: float ) -> void:
|
func bind_to_anchor(anchor_node: Node2D, radius: float ) -> void:
|
||||||
@ -67,12 +76,17 @@ func _on_EnemySkin_area_entered(area:Area2D) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func searching() -> Vector2:
|
func searching() -> Vector2:
|
||||||
|
detect_player()
|
||||||
|
|
||||||
if(is_on_floor()):
|
if(is_on_floor()):
|
||||||
if(jump_timer.is_stopped()):
|
if(jump_timer.is_stopped()):
|
||||||
jump_timer.start(rand_range(0.1,3.333))
|
if(target != null):
|
||||||
|
jump_timer.start(rand_range(0.3,1))
|
||||||
|
else:
|
||||||
|
jump_timer.start(rand_range(0.3,3.333))
|
||||||
if(in_air):
|
if(in_air):
|
||||||
in_air = false
|
in_air = false
|
||||||
print("Jump distance: ",global_position.x - start_x)
|
#print("Jump distance: ",global_position.x - start_x)
|
||||||
else:
|
else:
|
||||||
if(!in_air):
|
if(!in_air):
|
||||||
start_x = global_position.x
|
start_x = global_position.x
|
||||||
@ -83,24 +97,44 @@ func searching() -> Vector2:
|
|||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
|
func detect_player() -> void:
|
||||||
|
var player
|
||||||
|
if(!players.empty()):
|
||||||
|
player = players[0]
|
||||||
|
vision_raycast.cast_to = (player.global_position - global_position).normalized() * 100
|
||||||
|
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
|
||||||
|
var collider = vision_raycast.get_collider()
|
||||||
|
if(target == null && abs(ray_angle_to_facing) < PI/4 && collider != null && collider.is_in_group("player")):
|
||||||
|
target_lost_timer.stop()
|
||||||
|
target = collider
|
||||||
|
print("target found")
|
||||||
|
elif(target != null && target_lost_timer.is_stopped()):
|
||||||
|
target_lost_timer.start(3.0)
|
||||||
|
|
||||||
|
|
||||||
func sleeping() -> Vector2:
|
func sleeping() -> Vector2:
|
||||||
jump_timer.stop()
|
jump_timer.stop()
|
||||||
|
detect_player()
|
||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
|
func lose_target() -> void:
|
||||||
|
print("target lost")
|
||||||
|
target = null
|
||||||
|
|
||||||
|
|
||||||
func jump():
|
func jump():
|
||||||
var v: Vector2 = velocity_for_jump_distance()
|
var v: Vector2 = velocity_for_jump_distance()
|
||||||
var jump_height = (pow(v.length(), 2) * pow(sin(deg2rad(65)),2))/(2*_gravity)
|
var jump_height = (pow(v.length(), 2) * pow(sin(deg2rad(65)),2))/(2*_gravity)
|
||||||
print("Jump height: ", jump_height)
|
#print("Jump height: ", jump_height)
|
||||||
$CeilingRayCast.cast_to = Vector2(1.5*24 * get_facing_direction(), - jump_height)
|
|
||||||
velocity = v
|
velocity = v
|
||||||
|
|
||||||
if(is_bound):
|
if(is_bound):
|
||||||
var next_position = global_position + velocity * get_facing_direction() * current_delta
|
var next_position = global_position + velocity * get_facing_direction() * current_delta
|
||||||
var current_distance = global_position.distance_to(anchor.global_position)
|
var current_distance = global_position.distance_to(anchor.global_position)
|
||||||
var new_distance = next_position.distance_to(anchor.global_position)
|
var new_distance = next_position.distance_to(anchor.global_position)
|
||||||
print(current_distance)
|
#print(current_distance)
|
||||||
print(new_distance)
|
#print(new_distance)
|
||||||
if(new_distance >= movement_radius && new_distance > current_distance):
|
if(new_distance >= movement_radius && new_distance > current_distance):
|
||||||
if can_reverse_facing_direction():
|
if can_reverse_facing_direction():
|
||||||
reverse_facing_direction()
|
reverse_facing_direction()
|
||||||
@ -112,6 +146,8 @@ func jump():
|
|||||||
if sign(velocity.x) != get_facing_direction():
|
if sign(velocity.x) != get_facing_direction():
|
||||||
velocity.x *= -1
|
velocity.x *= -1
|
||||||
|
|
||||||
|
$CeilingRayCast.cast_to = Vector2(1.5*24 * get_facing_direction(), - jump_height)
|
||||||
|
|
||||||
|
|
||||||
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
|
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
|
||||||
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
|
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
|
||||||
|
|||||||
@ -70,6 +70,12 @@ enabled = true
|
|||||||
cast_to = Vector2( 10, 0 )
|
cast_to = Vector2( 10, 0 )
|
||||||
collision_mask = 56
|
collision_mask = 56
|
||||||
|
|
||||||
|
[node name="VisionRayCast" type="RayCast2D" parent="."]
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, -1 )
|
||||||
|
collision_mask = 9
|
||||||
|
collide_with_areas = true
|
||||||
|
|
||||||
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
|
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
|
||||||
position = Vector2( 0, 6.48802 )
|
position = Vector2( 0, 6.48802 )
|
||||||
scale = Vector2( 5.68128, 5.29182 )
|
scale = Vector2( 5.68128, 5.29182 )
|
||||||
@ -95,6 +101,7 @@ shape = SubResource( 2 )
|
|||||||
|
|
||||||
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
|
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
|
||||||
process_priority = -1
|
process_priority = -1
|
||||||
|
collision_layer = 2
|
||||||
collision_mask = 126
|
collision_mask = 126
|
||||||
|
|
||||||
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
|
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
|
||||||
|
|||||||
@ -72,9 +72,14 @@ func aiming():
|
|||||||
rotation = rotation - target_angle
|
rotation = rotation - target_angle
|
||||||
else:
|
else:
|
||||||
rotation = rotation - rotation_speed * sign(target_angle)
|
rotation = rotation - rotation_speed * sign(target_angle)
|
||||||
rotation = clamp(
|
if sign(angle_of_freedom) > 0:
|
||||||
rotation, original_rotation, original_rotation + angle_of_freedom
|
rotation = clamp(
|
||||||
)
|
rotation, original_rotation, original_rotation + angle_of_freedom
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
rotation = clamp(
|
||||||
|
rotation, original_rotation + angle_of_freedom, original_rotation
|
||||||
|
)
|
||||||
|
|
||||||
# Shoots and can loose the target
|
# Shoots and can loose the target
|
||||||
func shooting():
|
func shooting():
|
||||||
|
|||||||
@ -39,7 +39,7 @@ tracks/0/keys = {
|
|||||||
"times": PoolRealArray( 0, 6.1 ),
|
"times": PoolRealArray( 0, 6.1 ),
|
||||||
"transitions": PoolRealArray( 0.9, 1.1 ),
|
"transitions": PoolRealArray( 0.9, 1.1 ),
|
||||||
"update": 0,
|
"update": 0,
|
||||||
"values": [ 0.0, 90.0 ]
|
"values": [ 0.0, -45.0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Turret" type="KinematicBody2D" groups=["enemy"]]
|
[node name="Turret" type="KinematicBody2D" groups=["enemy"]]
|
||||||
|
|||||||
@ -21,4 +21,5 @@ shape = SubResource( 1 )
|
|||||||
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
||||||
position = Vector2( 0, 1.5 )
|
position = Vector2( 0, 1.5 )
|
||||||
scale = Vector2( 0.3, 0.3 )
|
scale = Vector2( 0.3, 0.3 )
|
||||||
|
bias = 0.108
|
||||||
softness = 0.1
|
softness = 0.1
|
||||||
|
|||||||
@ -43,18 +43,19 @@ position = Vector2( 231, 203 )
|
|||||||
|
|
||||||
[node name="Blobby" parent="." instance=ExtResource( 4 )]
|
[node name="Blobby" parent="." instance=ExtResource( 4 )]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2( 71.0069, 335.293 )
|
position = Vector2( -36, 336 )
|
||||||
scale = Vector2( 0.878906, 0.936025 )
|
scale = Vector2( 0.878906, 0.936025 )
|
||||||
|
|
||||||
[node name="AnimationTree" parent="Blobby/BlobbySprite" index="0"]
|
[node name="AnimationTree" parent="Blobby/BlobbySprite" index="0"]
|
||||||
parameters/playback = SubResource( 4 )
|
parameters/playback = SubResource( 4 )
|
||||||
|
|
||||||
[node name="BoundFrog" parent="." instance=ExtResource( 12 )]
|
[node name="BoundFrog" parent="." instance=ExtResource( 12 )]
|
||||||
position = Vector2( -15.9999, 324 )
|
position = Vector2( 57, 324 )
|
||||||
scale = Vector2( 0.878906, 0.936025 )
|
scale = Vector2( 0.878906, 0.936025 )
|
||||||
|
movement_radius = 300
|
||||||
|
|
||||||
[node name="WhatAreFrog" parent="BoundFrog" index="0"]
|
[node name="WhatAreFrog" parent="BoundFrog" index="0"]
|
||||||
position = Vector2( 54.6132, 0 )
|
position = Vector2( 187.733, 0 )
|
||||||
|
|
||||||
[node name="RopeAnchor" parent="BoundFrog" index="1"]
|
[node name="RopeAnchor" parent="BoundFrog" index="1"]
|
||||||
position = Vector2( 167.253, 9.61514 )
|
position = Vector2( 167.253, 9.61514 )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user