ai movement, ai hit and move treshhold added

This commit is contained in:
Jonas Mucke
2020-04-20 14:38:58 +02:00
parent 37ccf67677
commit d60f93db3e
5 changed files with 52 additions and 31 deletions

View File

@@ -20,7 +20,7 @@ radius = 18.0
height = 18.0
[sub_resource type="CapsuleShape2D" id=2]
radius = 18.0
radius = 20.0
height = 18.0
[sub_resource type="CircleShape2D" id=3]
@@ -448,7 +448,7 @@ states/move/position = Vector2( 143, 70 )
[node name="SlimeBoss" type="KinematicBody2D"]
collision_layer = 4
collision_mask = 3
collision_mask = 131
script = ExtResource( 4 )
__meta__ = {
"_edit_group_": true
@@ -491,9 +491,11 @@ collision_layer = 4
position = Vector2( 0, -15 )
shape = SubResource( 1 )
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
[node name="Hurtbox" parent="." groups=[
"HittableByPlayer",
] instance=ExtResource( 1 )]
collision_layer = 4
collision_mask = 0
collision_mask = 128
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
position = Vector2( 0, -15 )

View File

@@ -45,7 +45,7 @@ shape = SubResource( 2 )
[node name="Hitbox" parent="." instance=ExtResource( 4 )]
collision_layer = 16
damage = -0.5
damage = -1.5
[node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2( 0, -2 )

View File

@@ -33,9 +33,15 @@ var actionFieldUsed = false
var areaRefList = []
var threadTime = 0.6
var threadTime = 0.4
var threadDelta = 0.0
var hitDelta = 0.0
var hitTreshhold = 0.1
var aiDelta = 0.0
var aiTreshhold = 0.4
#calculates the sum of all present prios
func calcTotalPrio():
var sum = 0
@@ -70,7 +76,7 @@ func calcPrioTable():
#14+7 0.999
#updates heart and bonfire prio
func adjustPrio(currentHealth, maxHealth):
var prioVal = 10.0 - (float(currentHealth)/float(maxHealth))*10.0
var prioVal = 20.0 - (float(currentHealth)/float(maxHealth))*20.0
var bonfire = prioVal + 1
var hearts = prioVal
if(hearts < 0):
@@ -106,6 +112,7 @@ func getCost(field):
# curr - current position
# targ - a target position
func h_fn(curr, target):
var h = min(target[0]-curr[0],target[1]-curr[1])
return 0
# currCost - currentCost
@@ -143,21 +150,25 @@ func adjacent(currentPosition, can_roll = true):
continue
if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL):
if(i==0):
continue
if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==2):
continue
if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==5):
continue
if(grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==7):
continue
if(grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
@@ -267,11 +278,15 @@ func hit_or_miss(target, current, delta):
func movement_decider_ai(target, kindOfStep, delta):
var currentPosition = grid._pixel_to_grid_coords(global_position)
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
if hitDelta >= hitTreshhold && randf() <0.5:
hitDelta -= hitTreshhold
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
return
else:
if(kindOfStep==STEP):
@@ -288,12 +303,15 @@ func movement_decider_ai(target, kindOfStep, delta):
func movement_execution(delta):
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
return
if hitDelta >= hitTreshhold && randf() <0.5:
hitDelta -= hitTreshhold
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
return
if(targetFieldUsed):
var cur = grid._pixel_to_grid_coords(global_position)
@@ -320,16 +338,19 @@ func reset_exeution_state(delta):
func makeMove(delta):
if ExecutionState == AI_MOVE:
threadDelta = 0
var MoveAdvice = movement_calulcaotr()
if(MoveAdvice==null):
return
var target = MoveAdvice[1]
movement_decider_ai(target, MoveAdvice[0], delta)
func makeMove(delta):
hitDelta += delta
aiDelta+=delta
if(aiDelta>aiTreshhold):
if ExecutionState == AI_MOVE:
threadDelta = 0
var MoveAdvice = movement_calulcaotr()
if(MoveAdvice==null):
return
var target = MoveAdvice[1]
movement_decider_ai(target, MoveAdvice[0], delta)
elif ExecutionState == EXECUTING:
if ExecutionState == EXECUTING:
movement_execution(delta)
reset_exeution_state(delta)

View File

@@ -619,19 +619,17 @@ height = 0.2
radius = 4.03497
height = 9.42006
[sub_resource type="CircleShape2D" id=51]
[sub_resource type="CircleShape2D" id=49]
radius = 13.3924
[sub_resource type="DynamicFont" id=50]
size = 12
font_data = ExtResource( 6 )
[node name="Player" type="KinematicBody2D" groups=[
"hero",
]]
collision_mask = 14
script = ExtResource( 1 )
ROLL_SPEED = 120
FRICTION = 270
@@ -724,7 +722,7 @@ damage = 0.0
[node name="CollisionShape2D" parent="Pivot/SwordRange" index="0"]
position = Vector2( 0, -4.56405 )
shape = SubResource( 51 )
shape = SubResource( 49 )
[node name="DebugLabel" type="Label" parent="."]
margin_left = -8.12021

View File

@@ -21,7 +21,7 @@ region_enabled = true
region_rect = Rect2( 0, 0, 1280, 720 )
[node name="Background" parent="." instance=ExtResource( 7 )]
frame = 20
frame = 41
[node name="FloorTileMap" type="TileMap" parent="."]
visible = false
@@ -40,7 +40,7 @@ __meta__ = {
[node name="YSort" type="YSort" parent="."]
[node name="Bonfire" parent="YSort" instance=ExtResource( 10 )]
position = Vector2( 265.543, -16 )
position = Vector2( 448, 32 )
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
position = Vector2( 344, 125.768 )