1
我有三個物體,obj_player,obj_enemy,obj_wall。現在,我有來自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點以內。我不知道是否有一個解決方法,讓敵人停止射擊,如果他們之間有一堵牆。感謝那些會回覆的人。我知道有gmc論壇,我希望有人能幫助我。
我認爲你需要創建,如果牆壁確定的函數的每一個角落之間行介於'is_wall_between'之間,然後將其添加到'if'語句中,如標題所示的if(target_distance <64 &&!is_wall_between())' –
- 首先不要給他們一把槍。但是,如果你是美國人,他們喜歡武裝全世界,這不是一種選擇 - 只是一種觀察。 –