Random Spawn Safe Distance from Player?

billybarringtonbillybarrington Member Posts: 5
edited November -1 in Working with GS (Mac)
Hello,

I have enemies spawning randomly within the scene, occasionally the enemies spawn on or unavoidably close to the player, instant death! I don't think I can randomly spawn the enemies relative to the player as the player can move around most of the scene, thus sometimes enemies would spawn offscreen, which I can't have happen.

So, how can one randomly spawn enemies in the scene a safe distance from the player?

Comments

  • InLikeFlynnInLikeFlynn Member Posts: 171
    You'll want to make your player broadcast it's position by constraining player.position.x and player.position.y to attributes that can be accessed by any other actor.

    If you want them a safe distance from your player, you might want to divide your screen into quadrants or halves, then spawn in the area your player is not in. Eg:
    Rule: if playerPositionX >240
    spawn the enemy at x = Random (0, 200)
    otherwise
    spawn the enemy at x = Random (280, 480)
Sign In or Register to comment.