Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: jeanfabre on July 30, 2015, 02:03:25 AM

Title: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on July 30, 2015, 02:03:25 AM
Hi Everyone,

 A New sample is available on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181), this time showing how to build a Virtual Joystick with just the new Unity UI and PlayMaker, so you get a complete solution that you can then further improve/modify to your needs, but as is it will be already pretty solid.

(https://i.imgur.com/eXtSQj7.gif)

You can download it manually here (https://github.com/jeanfabre/PlayMaker--Unity--UI/raw/master/PlayMaker/Ecosystem/Custom%20Samples/uGui/uGuiJoystick.unitypackage)

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: clandestine on July 30, 2015, 07:02:08 AM
This is awesome man, wow!!!
U4.6 and up right?

A million thanks!
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on July 30, 2015, 07:08:08 AM
Hi

 yes, 4.6+ and 5 ( not tested on 5, but should work, it's simple a simple UI rig after all).

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 01, 2015, 03:34:25 PM
how come the fsm has no actions in its state? I only see events in the events tab...theres nothing.. any possibility you can show us how to set this thing up? I just want to get it to the state u showed in the screenshot - right now i can drop an invisible prefab onto the scene and literally thats it. Perhaps include a sample scene? Thanks
Title: Re: Virtual Joystick Ecosystem Sample
Post by: djaydino on August 01, 2015, 04:13:27 PM
Hi,
That fsm is just there to work with the ugui system you can just ignore that object/fsm
but do not disable or remove.
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 02, 2015, 04:01:08 AM
So how do I actually get the joysticks? there is no joystick prefab - do I have to download something additionally? I just want to have what jean showed in his screenshot. Thanks
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on August 02, 2015, 04:13:16 AM
Hi,

 There is a prefab, it's in the custom sample folder next to the sceneit's called "UI Joystick".

 When you deal with Unity UI, everything has to be within a Canvas, so go explore the content of the canvas and you'll find what you see on screen. you'll find the left josytick in Canvas/Left Joystick Panel/UI Joystick

The other option is to select from the scene view the element you want to look at.

I am also confused by your statement, have you loaded the scene uGuiJoystick? Is it working when you press play? do you see the joysticks and the feedback as you drag the joysticks around?

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 02, 2015, 04:54:52 AM
Ah, I see, I was just having difficulty finding the uGUI Joystick scene - you made it clear now. Thanks. Two quick questions: can I use both joysticks at the same time if on a mobile device, and why did u use unity 4.6 not 5 to make this? thanks
Title: Re: Virtual Joystick Ecosystem Sample
Post by: smartgames on August 02, 2015, 06:04:16 AM
Hi,

 There is a prefab, it's in the custom sample folder next to the sceneit's called "UI Joystick".

 When you deal with Unity UI, everything has to be within a Canvas, so go explore the content of the canvas and you'll find what you see on screen. you'll find the left josytick in Canvas/Left Joystick Panel/UI Joystick

The other option is to select from the scene view the element you want to look at.

I am also confused by your statement, have you loaded the scene uGuiJoystick? Is it working when you press play? do you see the joysticks and the feedback as you drag the joysticks around?

Bye,

 Jean
i want to know how to assign this controller to the player object i want to move ?
i downloaded the joystick and tried it but i dont know how to deal with the object i want to move ?
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on August 02, 2015, 06:06:04 AM
Hi,

yes, the examples compile on mobile, I tested it. basically you can have as many joysticks you want on screen, they will work as expected ( they rely under the hood with the Unity event systenm so you are safe).

 I always try to make samples with the lowest Unity version so that everyone benefits from it, If I make it for u5, u4 users would not be able to use it, and it allows users to report any issues with new releases, and then I modify the content to work across the board.

 Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on August 02, 2015, 06:07:53 AM
Hi,

 either you modify the prefab so that it talks to the player, or you do the opposite, your player go get the input on the joystick. Check the panel that displays the infos for both joystick, they use "Get Fsm float" action, targeting the joystick and track the input they want. Do the same.

Bye,

 Jean

Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 02, 2015, 06:12:16 AM
ok but what action would you actually use do the movement? I have a cube set up with get fsm float of the x and y values, I just don't know what action should be used to convert the joystick input values to movement. Could you tell me how to get a simple rigid body cube to move using the joystick. Thanks
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on August 03, 2015, 04:52:51 AM
Hi,

You should use this input value coming from the joystick like the regular Unity Input.

Simply use a translate action, in the value of the translation use the input value multiplied by a speed float, and make the translation works per seconds.


 Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 03, 2015, 06:14:18 AM
I think I'm not understanding you, which input value should I be using? Ive attached a screenshot to show the fsm I set up on the cube. I use a get fsm float for x and y values and save them as float variables, then multiply it by 5, then use translate x with the x float variable and translate z with the y float variable. It doesn't look like the cube is picking up the input from the joysticks. Its really weird all the logic looks like it should be working. I've even tested the cube to make sure translate works, I've tried putting the cube in and out of the canvas in the hierarchy, I've even tried making the x and y variables of the joystick globals and then directly access the globals from the cube using the translate, and I've tried using set velocity, controller move, and of course translate. None of these seem to work, so its definitely a problem with the cube not picking up the input.
Title: Re: Virtual Joystick Ecosystem Sample
Post by: jeanfabre on August 03, 2015, 02:54:16 PM
Hi,

 The bottom is missing so I can't see if you are properly setting up the translate.

 Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 03, 2015, 03:52:07 PM
Here it is:
Title: Re: Virtual Joystick Ecosystem Sample
Post by: ETGgames on August 04, 2015, 04:41:16 PM
Ok, here it is
Title: Re: Virtual Joystick Ecosystem Sample
Post by: PunkMunkey on August 09, 2015, 11:29:45 PM
This is absolutely fantastic! Thank you so much. This just saved me $50 on buying something from the asset store. This does the same thing so much simpler.
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on July 15, 2019, 03:40:53 AM
Hi Everyone,

 ok, so this sample has been updated to work with the PlayMaker's built in UI support. Thanks for Djaydino for the porting.

(https://i.imgur.com/eXtSQj7.gif)

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: Seiryu33 on October 23, 2019, 02:28:06 AM
Hi. Is there a tutorial on using it? I'm trying to implement virtual controls for Android, and got really confused about where to even start. Using my own assets doesn't give me the responsiveness I want. I drag the prefab into the scene and nothing appears in scene view. I'm totally lost.
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on October 29, 2019, 03:45:35 AM
Hi,

 It's actually quite simple, don't over think this.

 you need to drag the UI joystick prefab in a canvas, or UI panel, if you don't see it in the Game view, make sure it's placed properly.

then,
- create a new gameobject
- add a new Fsm
- in the start state, add an action GetFsmFloat
- target the joystick prefab instance, and get for example the x value of the fsm "Joystick interface", the GetFsmFloat action should guide you to pick the fsm and the value once you have referenced the UI joystick instance.
- make sure the GetFsmFloat action runs everyframe

that's it, now you have the x values of the joystick interface.

check out the object Panel X to see how it's done.

Bye,

 Jean



Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on November 08, 2019, 10:25:26 AM
I was able to setup the right mobile control stick for my camera quite easily but having trouble figuring out how to setup the left one so that my character will move.

Please view the screenshot of the current setup.

Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on November 11, 2019, 02:32:11 AM
Hi,

It seems you are using GetAxis action instead of using getFsmFloat and get the input from the joystick fsm. I think that's all there is to it.

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on November 14, 2019, 08:11:32 AM
Although yes I can get the X and Y floats from the joystick FSM

my character will only walk forwards.

I'm thinking that this is due to my current animator setup, as he is always walking forwards.

The input direction compass, however, ensures that the character is looking in the right direction.

The Camera autolook is a child of the input direction compass, in the movement fsm with the "smooth look at" pointed to this object.

Should I be using the floats in the joystick FSM here as well?

But what about the relative to main camera, how does this fit in?


 
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on November 24, 2019, 04:45:18 PM
So I have tried to use the 3d position and it kinda works,

But it only allows the movement to be left and right. No forward or backward.

I would very much appreciate jeans help and advise.



Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on November 25, 2019, 01:23:12 AM
Hi,

 does it work if you swap back to using get axis input?

If your input coming from the joystick indicates a vertical value between -1 and 1, then it's not a problem with the joystick input itself. Can you verify this?

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on November 25, 2019, 12:18:43 PM
using the 3d position x -1 = move right and x 1 = move left.

It does show y 1 as up on the joystick but the character does not change direction.

It also shows y -1 as down on the joystick but the character does not change direction.

When I switch back to using the get axis input and using keyboard controls.

It shows x 1 = move Right, x -1 = move left

using up arrow Z = 1, using down arrow Z = -1

Note if I use a controller joystick these values are the same.



Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on November 25, 2019, 01:18:13 PM
Hi,

 ok, I see: the getAxisInput, outputs ( vector3(x input,0,y input), but the joystick outpus( vector3(x input, y input),

you just need to copy the y value to the z right after you get the value from the joystick, or edit the joystick fsm, so that it output in the z component of the vector3.

Bye,

 Jean


Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on November 25, 2019, 04:48:19 PM
So I edited the Thumb interactive FSM as can be seen in the attached screenshot.

It works a treat.

However, this is only one element that needs changing as I will need to create a new movement FSM for the android/mobile system.

Plus the new canvas buttons to aim, shoot reload and grenades.

But once I get this all working I will have a rather good system.

keyboard/mouse control

Joystick control with the ability to remap the buttons.

Mobile controls.

I will do a special build on web gl and post it with my updates.

Can I post a link here when finished?



Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: jeanfabre on November 26, 2019, 01:29:16 AM
Hi,

 of course, sharing is caring :) so feel free to share your work, it will be appreciated.

Bye,

 Jean
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: colpolstudios on December 02, 2019, 10:19:13 AM
https://simmer.io/@colpolstudios/mechanim-simple-ik-v-07 (https://simmer.io/@colpolstudios/mechanim-simple-ik-v-07)

Please note that the restart button is only there so that you can go back and choose a different method of control.

You would not have this option normally.

I have yet to test on an actual phone but don't forsee any issues.

Let me know what you think of the controls.

Feedback is valuable.
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: playmakertester on March 02, 2021, 12:15:08 AM
Hi,

When I import my project, there is error say

 'Application' does not contain a definition for 'isWebPlayer'

Can I ask how to handle it?
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: playmakertester on March 02, 2021, 12:17:58 AM
The target error code can be found here.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
// REMOVED ECOSYSTEM FLAG TO AVOID DUPLICATES IN ECOSYSTEM BROWSER, AS IT SEARCHED THIS REP AS WELL


using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[Tooltip("Open a Url link in the browser")]
public class ApplicationOpenUrl : FsmStateAction
{

[RequiredField]
public FsmString url;

[Tooltip("When in webPlayer, will open a new window, define the name of that window here.")]
public FsmString WebWindowTitle;

public override void Reset()
{
url ="";
}

public override void OnEnter()
{
if (Application.isWebPlayer)
{
#if UNITY_IPHONE
#else
Application.ExternalEval("window.open('"+url+"','"+WebWindowTitle.Value+"')");
#endif
}else{
Application.OpenURL(url.Value);
}
Finish();
}
}
}
Title: Re: Virtual Joystick Ecosystem Sample [ECOSYSTEM] [JULY 2019]
Post by: playmakertester on March 02, 2021, 12:21:31 AM
if (Application.isWebPlayer)

I changed it like this and it worked.

if (Application.platform == RuntimePlatform.WebGLPlayer)

Please let me know if there are any problems.