Actor checks for avaliable space

I have a "controller" in my game that takes care of spawning actors in a random location in the scene. I wanted to know if there is a way to have an actor check to make sure it doesn't overlap another actor, before it spawns?

Currently I just have my timer that spawns the actor every 1 sec, in a random x and y location, using the random expression.

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    An easy work around is to spawn the actor and then evaluate if it's overlapping something. For example, in your spawned actor create a rule that states:

    When actor overlaps or collides with YourActor

    • Change Attribute self.Position.X to random(x,y)
    • Change Attribute self.Position.Y to random(x,y)

    You would then evaluate again and again until the rule doesn't trigger. Then you know that you're not overlapping another spawned actor.

  • GamingtilDawnGamingtilDawn Member Posts: 104

    @Braydon_SFX

    Ok thank you that did work. Only thing now is when it does spawn on another actor, it changes locations but kind of flashes (like a glitch), then moves both actors.

  • GamingtilDawnGamingtilDawn Member Posts: 104

    I was actually just watching video I just found by @tshirtbooth. It's exactly what I am trying to accomplish but one of the steps seems very time consuming lol. He suggested making a table that had all the spawn points I want. That's alot os points to add to the table. :s Im hoping that since the video is 3 yrs old it has a little bit faster way lol

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @GamingtilDawn said:
    Ok thank you that did work. Only thing now is when it does spawn on another actor, it changes locations but kind of flashes (like a glitch), then moves both actors.

    Spawn an invisible utility actor that seeks out the position, when located it spawns the main actor into a 'safe' location - the utility actor is set so that it does not collide with (so will not move) the main actor.

    Utility actor . . . .

    When actor overlaps or collides with the main actor then do @Braydon_SFX's code
    Otherwise spawn main actor and destroy (itself).

  • GamingtilDawnGamingtilDawn Member Posts: 104

    @Socks

    Thank you! That helped with the small issue I had.

Sign In or Register to comment.