Post

39Updating the drone

这节完善敌人系统里的drone

drone特点

一些细节

  • 向player加速移动
1
2
3
#在player进入边界,用补间动画,在短时间内将 speed 属性从0调整到600
var tween = create_tween()
tween.tween_property(self, "speed",max_speed, 6)
  • 判断是否与其他物体碰撞:

move_and_collide( velocity*delta )返回一个 KinematicCollision2D,其中包含有关停止时或沿运动触摸另一个实体时碰撞的信息。

  • drone爆炸后,drone的爆炸效果仍然跟随玩家问题
1
2
3
4
5
6
7
#他的方法是通过速度乘数来实现:默认speed_multiplier=1,击中speed_multiplier=0那么就不会移动
velocity = (Globals.player_pos - position).normalized() * speed * speed_multiplier

#实际可通过explosion_active判断,那么下面的代码则不会执行,drone也不会移动
func _process(delta):
    if active and  not explosion_active:
        #.....
  • 爆炸殃及池鱼。这个实现基本和grenade差不多
1
2
3
4
5
6
7
if explosion_active:
    var targets = get_tree().get_nodes_in_group("Container")\
                + get_tree().get_nodes_in_group("Entity")
    for it in targets:
        if "hit" in it\
            and it.global_position.distance_to(global_position)<400:
            it.hit()
This post is licensed under CC BY 4.0 by the author.