obj_player、obj_enemy、obj_wall の 3 つのオブジェクトがあります。今、私は gmc フォーラムからこのコードを持っています。
shoot_cooldown -= 1; //Lower the shooting cooldown timer
if (shoot_cooldown < 0) then shoot_cooldown = 0 //Prevents timer from counting down further than 0.
target_distance = distance_to_object(obj_player); //Distance to the player from enemy.
if (target_distance < 64) //If player within the range of enemy
{
//image_angle = point_direction(x,y,obj_player.x,obj_player.y); //Enemy faces the player.
if (shoot_cooldown == 0) //If enemy can shoot (cooldown ready)
{
bullet = instance_create(x,y,obj_bullet); //Create a bullet relative to enemy
bullet.direction = point_direction(x,y,obj_player.x,obj_player.y); //Shoot it towards player
bullet.speed = 3; //Give it speed
shoot_cooldown = 50; //Set the new cooldown time between low and high thresholds.
}
}
これは完全に機能します。ただし、obj_player と obj_enemy のサイズは 64x64 です。私のコードでは、プレイヤーと敵の間の距離が 64pix 以下の場合、敵は弾丸を発射します。これで、obj_wall のサイズは 32x32 になりました。プレイヤーが壁の反対側にいる場合、敵はプレイヤーを「検出できない」ため、敵は弾丸を発射してはなりません。しかし、プレイヤーが 64 pix 以内にいるため、敵は依然として弾丸を発射します。敵との間に壁がある場合、敵の発砲を停止させる回避策はあるのだろうか。返信してくれる人ありがとう。gmc フォーラムがあることは知っています。誰かがここでも私を助けてくれることを願っています。