Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Grofit on January 14, 2013, 05:16:09 PM
-
Hi all,
I am new to playmaker, brilliant bit of kit though!
I am working on a simple bit of AI at the moment where things should react to an explosion or some other event. As part of this I want *something* to happen then everything within a radius be alerted to this.
As part of this I thought I would write a custom event which would FindAllGameObjectsWithinRadius, however I cannot find any information on how the best way to store the found objects would be, as ideally I would want to allow them to be stored to make the custom action more re-useable.
However if this is not that doable I am more than happy to make something like SendEventToGameObjectsInRadius where it would just send an event from inside the code, but I was wondering what everyones thoughts on this subject are.
As ideally the game objects nearby which are of a certain type (tagged) would then react to the event, by either freaking out and running for cover or running to put the fire out etc.
-
fastest way i would know of is to make a global event something like "freakout" or whatever you want to call it and then set up a collider/trigger where on trigger stay --> explosion state --> get FSM event "freak out" and then make FSM state for all those seperate game objects to flow into what you want them to do.
this would probably be an effective way of localizing the event to just that radius where those game objects are around the explosion. Or maybe set up an alternate FSM to compare distance to that gameobject with compare tag so once they get in that radius or close to it their behavior will change.
I believe there is the ability to send server wide event calls but i think in this situation it will only cause problems since i dont believe all your explosions or locations are near each other. Besides if you take this approach then sending a server wide event will trigger every AI in the scene not just those around the area.
but yeah prob best woudl be having them compare distance and tags, within x amount of distance act a certain way, on trigger enter/stay send state action, explosion event send Global event to game objects, trigger "freakout" fsm for independant game object action. just be sure to apply true/false statement and make it so if distance =/= to radius -> continue normal behavior, if distance is in radius then make true for events.
you can save the FSM template and just paste it over to the other game objects to save time and change minor behaviors. Apply to prefab and you should be good.
This way if you match the radius with the distance if they are outside they are un-effected by the event and if inside the radius react how you would like them too.
Thats how i would go about it, but like you I'm new to Playmaker as well.. just some insight from another perspective.
-
Hi,
I would check TargetPro for this. as it has everything to do that in a very powerful way.
https://hutonggames.fogbugz.com/default.asp?W993
bye,
Jean
-
Thanks for the info, ideally I dont want to have to buy anything extra just to be able to find all game objects within a radius as Unity provides that functionality out of the box, the question is more around can I store that array of objects as a variable to use later, as most actions seem to apply to a single game object, so im not sure if the system could apply the given action to all game objects within the variable... well unless I wrote some more custom actions, here is what I have ended up with:
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets all game objects within a given spherical radius.")]
public class SendEventToGameObjectsWithinRadius : FsmStateAction
{
[RequiredField]
[Tooltip("The owner object.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmFloat)]
[Tooltip("The radius to search for objects within.")]
public FsmFloat radius;
[UIHint(UIHint.Tag)]
[Tooltip("Tagged objects to use.")]
public FsmString tag;
[RequiredField]
[Tooltip("Event to raise on objects.")]
public FsmEvent eventToRaise;
public override void Reset()
{
gameObject = null;
radius = 10.0f;
tag = string.Empty;
eventToRaise = null;
}
public override void OnEnter()
{
IEnumerable<Collider> colliders = Physics.OverlapSphere(gameObject.GameObject.Value.transform.position, radius.Value);
if(!string.IsNullOrEmpty(tag.Value))
{ colliders = colliders.Where(x => x.tag.Equals(tag.Value)); }
foreach (var collider in colliders)
{ collider.GetComponent<PlayMakerFSM>().SendEvent(eventToRaise.Name); }
}
}
}
-
Hi,
Yes, I simply recommend what I feel is the right tool for the task ( not affiliated for the record :) )
For working with arrays, I recommend ArrayMaker ( this one, I am affiliated... I did it ;D and it's free!), it's all done especially for PlayMaker.
https://hutonggames.fogbugz.com/default.asp?W715
bye,
Jean
-
Hi,
I would check TargetPro for this. as it has everything to do that in a very powerful way.
https://hutonggames.fogbugz.com/default.asp?W993
bye,
Jean
Hi Jean.
Could you please update the actions?
It seems like the author has made some modifications:
http://docs.triggereventpro.path-o-logical.com/Doxygen/html/page_target_pro_upgrade_guide.html (http://docs.triggereventpro.path-o-logical.com/Doxygen/html/page_target_pro_upgrade_guide.html)
Thanks
-
Hi,
Yeah, the changes are very important, so it means a deep rewrite, so I am waiting for a time slot to be able to concentrate on this.
Please up vote the trello task:
https://trello.com/c/kr41Sm39/94-triggereventpro
Bye,
Jean