playMaker

Author Topic: How to randomly generate enemies and avoid obstacles  (Read 1013 times)

bbs950064

  • Playmaker Newbie
  • *
  • Posts: 12
How to randomly generate enemies and avoid obstacles
« on: December 03, 2020, 09:06:08 AM »
sorry for first question, i am new for PlayMaker

i want to make enemies generate in a range, but wont generate enemies in the obstacles, and enemies are too far away from the player, will disappear by themselves



the player is movable, and the enemies will chase the player

but I don't know how to calculate the distance. i currently only know how to use Trigger, which seems like a bad idea.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to randomly generate enemies and avoid obstacles
« Reply #1 on: December 03, 2020, 09:15:19 AM »
Get Distance (Distance), then Compare Float (Distance < Range = Generate, Distance > DisappearingRange = Disappear)
Available for Playmaker work

bbs950064

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How to randomly generate enemies and avoid obstacles
« Reply #2 on: December 04, 2020, 08:14:55 AM »
Is there a more detailed approach? Sorry, I am not familiar with the concept of programming yet, and I don’t know what the unit of Distance is using when setting it.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to randomly generate enemies and avoid obstacles
« Reply #3 on: December 04, 2020, 08:46:53 AM »
You need to have a spawner that will get distance from player in regular intervals. It will store it in a float variable. Each time you measure distance, compare it to another variable which holds the desired distance below which the enemy will be spawned.

Enemies can have a similar system, they measure distance from player in regular intervals, when that distance is above the desired threshold, trigge their despawn process.

It can be done in many different ways, but if you're a beginner, this is the easiest one (though not the most efficient one).

Actions you will need are Get Distance and Compare Float for measuring and comparing values. Since you are new, for now use Create Object and Destroy Object for creating and destroying enemies.
Available for Playmaker work

bbs950064

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How to randomly generate enemies and avoid obstacles
« Reply #4 on: December 04, 2020, 10:19:29 AM »
i put the Get Distance on a emptyobject to using spawn enemies, it need a gameobject target , what should i do ? if this FSM is use to spawn enemies, the target should be a range number does it ?
if it does, how to save the range number? i only know how to save a point, or using trigger

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How to randomly generate enemies and avoid obstacles
« Reply #5 on: December 04, 2020, 10:42:47 AM »
You put get distance on an object that you will measure from, in this case a gameobject that will spawn enemies. Target is the player, result is the distance. Save them into variables (DistanceFromPlayer as a float, DistanceForSpawning as a float). Then put Compare Float and select you variables, DistanceFromPlayer first, DistanceForSpawning second. If DistamceFromPlayer equal or less then DistanceForSpawnin, then go to next wvwnt which will hold Create Object.

To get Player, for beginning you can use Find Game Object and type in Player game object name.

You should take a look at some tutorials.
Available for Playmaker work

bbs950064

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How to randomly generate enemies and avoid obstacles
« Reply #6 on: December 04, 2020, 11:17:15 AM »
thanks!! i did it!! now my enemies will destroy itself when too faraway from player.
but i still dont know how to randomly generate enemies in the range, i mean destroy  is easier because both are gameobject, but generate enemies is player compare a range, not generate on any gameobject, is generate in a range.

bbs950064

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How to randomly generate enemies and avoid obstacles
« Reply #7 on: December 04, 2020, 02:56:34 PM »
Sorry, I wanted to put fsm on an emptyobject because I wanted to spawn enemies . Maybe it would be better to make an emptyobject, so I didn’t put it on the player or the enemies.
Because I made Destroying Enemies FSM is using Destroy Object.
So when I making a Creating Enemies, I thought it had no need to attach to other objects, so i put it on an emptyobject.

I am sorry that my logic is wrong, I hope you can help me solve the Creating Enemies problem