Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Krillan87 on December 04, 2020, 04:51:48 AM

Title: Actions that ask for gameobject instead of a vector
Post by: Krillan87 on December 04, 2020, 04:51:48 AM
Hi,

I have a question that I've been thinking of lately. A lot of actions has one input field that requires a Game Object. A lot of times I find myself unable to use a lot of these actions because I do not have a Game Object but instead a Vector/world position instead, are there a obvious easy way to "convert" this that I am miss?

A lot of times it is because i get a "hit point" with a raycast.

For instance:
I get a "Hit Point" from a raycast and want to measure the "Transform distance" in Y from my player to the hitpoint. The action requires me to use two targets that both are game objects, so I can't use the action.

Do I really need an almost identical, custom action, that just allows me to input a vector or is there another way to do this with other actions? Like a "convert Vector2 to a imaginative game object"

Thanks,
Christian
Title: Re: Actions that ask for gameobject instead of a vector
Post by: Fat Pug Studio on December 04, 2020, 08:49:50 AM
Create an object on runtime which will use the hitpoint as position where it will be created then do with that object as you wish and destroy it/disable it. It's a usual pattern, i use that a lot in my game for exact purpose and some other games i freelanced on use the exact same thing.
Title: Re: Actions that ask for gameobject instead of a vector
Post by: Krillan87 on December 04, 2020, 03:48:02 PM
Create an object on runtime which will use the hitpoint as position where it will be created then do with that object as you wish and destroy it/disable it. It's a usual pattern, i use that a lot in my game for exact purpose and some other games i freelanced on use the exact same thing.

Yeah I understand that there are a lot of workaround for this but that's the case, they are workarounds. It sounds very weird that you should do that instead of inputing a vector. I have a hard time believing that this is the best practice. no?
Title: Re: Actions that ask for gameobject instead of a vector
Post by: Alex Chouls on December 04, 2020, 08:00:38 PM
I assume in your example you're talking about Get Transform Distance from the ecosystem? Actions like that are trying to cover common use cases while hiding the details, but you can generally do the same thing with a few lower-level actions.

E.g., in your example, you can probably use Inverse Transform Point (to transform from global space to a GameObject's local space), Vector3 Subtract (to get vector to the hit point), and GetVector3XYZ (to get the y component).

As we identify common use cases we try to add higher-level actions that combine a few actions into a single action. Or we can add parameter "overloads" to an existing action e.g. allowing the action to use a GameObject and/or a Vector3 (quite a lot of actions working with position do this).

It sounds like this might be a case where it's worth us adding a Position parameter, or maybe designing a new action that is more flexible...

There are some systemic ways that we make actions more flexible. For example, you can convert between variable types in variable selection popups. But there's no conversion from Vector3 to GameObject. That's essentially what krmko's workaround does.

Another approach: In 1.9.1 Templates can have input and output variables, so you could essentially make your own action from lower-level actions, save them in a template, and re-use that wherever you need it.

Hope this helps some. It is an ongoing battle to balance ease-of-use and flexibility; high-level actions and low-level actions. But your feedback helps us identify areas to focus on!
Title: Re: Actions that ask for gameobject instead of a vector
Post by: Alex Chouls on December 04, 2020, 09:56:49 PM
It does seem like getting distance along a specific axis is a common use case, so I added a GetDistanceXYZ action. I've attached it if you want to give it a go...

I'll probably add a Position parameter that works the same way to GetDistance also.