Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Dan on August 04, 2016, 03:14:00 AM

Title: Vector Math Problem[SOLVED]
Post by: Dan on August 04, 2016, 03:14:00 AM
Ok, I could use some help.

Problem: Using vector math, determine player location and home location. Give update on the GUI with where the player is in relation to 'home'. The player moves with WASD keys.


I attached a script that we did in a course. I'm trying to understand how to do this with playMaker which would replace the script. Also, in the script it has different key assignments but it should be simple enough to change that.

Title: Re: Vector Math Problem
Post by: jeanfabre on August 11, 2016, 08:19:02 AM
Hi,

 Ok. I'll create a sample for early next week. Please ping me if I haven't replied on tuesday, thanks  :)

 Bye,

 Jean
Title: Re: Vector Math Problem
Post by: Dan on August 11, 2016, 10:54:27 AM
Very cool, thanks!   :)
Title: Re: Vector Math Problem
Post by: jeanfabre on August 17, 2016, 12:04:59 AM
Hi,

 Ok, here we go :)

One fsm only. If the game gets more complex, you'll likely need to split up into two fsm, one for UI management, and one for the game itself, but as a starter, you'll have the exactly behaviour of your script, done in PlayMaker. I also added some features, but mainly for having an easier UI system ( Menu, game, win)

Let me know if you have questions. You'll find that this is all using very basic actions, no custom actions of fancy tricks.

The package attached use the latest version of PlayMaker ( 1.8.2) and works from Unity 4.7 onwards.

 Bye,

 Jean


Title: Re: Vector Math Problem
Post by: Dan on August 17, 2016, 02:11:52 AM
This has helped a lot! I really appreciate it. Thanks!
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on August 24, 2016, 02:26:35 PM
I'm trying to update the steps while moving the player rather than each time the key is pressed but not having any luck.

Currently if I press the 'W' key then it shows one step forward and it updates the value on the GUI. For example, 'After 1 steps, you are 5.39 away from home.'

How do I wire this so as I move the player around it updates the steps automatically? If I'm running forward then I would hold the 'W' key (not press it each time for each step). And if I press 'W' + SHIFT then I would run faster which would represent more steps.

Is the answer in the GetKeyDown?
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on August 29, 2016, 04:27:58 AM
Hi,

That would be a very different design approach, you should indeed listen to inputs instead of keys, and so you would have a value ranging from -1 to 1 ( left or right, up or down).

 use the action "getAxisVector" for this, it will return you a vector representing two inputs ( usually the joystick input), and then you use that to move the player around, this is different then listening to a key press and do a single action with it.

 Experiment with this, if you are still stuck, I'll do another sample with this design instead.

Bye,

 Jean

Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on August 29, 2016, 03:53:46 PM
Hi Jean,

I think I will leave it the way it is for this project. Particularly since that is the design approach intended for this course.

I do have a couple of questions though if you have a moment.

1. After completing the game, and then clicking 'Back To Menu', and then 'Start Game' to play again, it retains the value of steps.

For example, You won in 9 steps. Then play the game again and the GUI reads after 9 steps you are x.xx away from home. How do I reset the value to read After 0 steps, you are 5.10 away from home?

The 'Reset Data' state has the action 'Set Vector2 Value' which sets the Vector2 Variable to Player Location. The Vector2 value is x=5 and y=1. I thought this would do it but it doesn't.


2. On the 'Welcome Text' state, an action called 'GUI Layout Label' has the text "Home Location x string". As far as I can tell, it simply displays that string "Home Location x string". I disabled that action so the player does not have that displayed. Does it have functionality that I'm overlooking?

Thanks,
Dan
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on August 29, 2016, 11:17:55 PM
Hi,

 1: yes, simply use "set Int" in the reset state and set the number of steps to 0, that's all.

2: I did a one to one conversion of your script, and in your script you do display the x value of the home location, so I wanted to show you as well how to do that.

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on August 30, 2016, 06:47:27 AM
1) Ahh, that is an easy fix. 'Set Int Value' for numberOfSteps was all that was needed.

2) Display the x value of the home location.

I'm not seeing how to display the x value of the Home Location. I see on the 'Welcome Text' where the GUI Layout Text Label has the text 'Home Location x string'. However, it displays that string and not the value of the Home Location.

Thanks,
Dan
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on August 31, 2016, 01:02:01 AM
Hi,

 Can you make a screenshot of your game view, cause here it's working fine.

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on August 31, 2016, 05:50:24 AM
Hi Jean,

Sure thing, screenshot attached. I placed a red arrow towards the text. It is displayed prior to game play.

Thanks,
Dan
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on September 01, 2016, 10:31:46 PM
Hi,

in the screenshot is says "HomeLocation.x = 2"

 ok, 2 is indeed the x value of the home location, so this is right, do we agree on that?
 
In the "Welcome Text" there is two actions to get this.
-- Convert Float to String which convert 2 into "2"
-- Build String which builds a string made out of "HomeLocation.x =" + "2"

then it's outputed using a gui text label.

 Are you ok with this process? If not, what would you like seeing being outputed "2,3" or something like that?

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 03, 2016, 05:38:29 PM
Hi Jean,

I have to admit I am not getting it. I'm sure it is fundamental and I'm overlooking something very basic. Perhaps I need to think about it for a time until the light bulb comes on.

I listed out the states, events, variables and variable types in an effort to understand this better but still not seeing it the same way. That can be found here: https://dan-m.com/index.php/unity/playmaker/gohome-elements (https://dan-m.com/index.php/unity/playmaker/gohome-elements).

Quote
ok, 2 is indeed the x value of the home location, so this is right, do we agree on that?

I don't see where 2 has the x value for home location. It is the output that has me confused because it outputs "Home Location x string". So the player will see the text "Home Location x string" before hitting play. I suppose that leads me to the question, is it necessary to do the GUI Layout Text Label for Home Location x string?

Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 03, 2016, 06:41:56 PM
This might help to show what I am referring to:

http://dan-m.com/unity/gohome/

It is the GoHome game published to Web GL. The player arrives and sees the following text "Home Location x string". The player may wonder what this means.
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on September 05, 2016, 01:13:26 AM
Hi,

 ok, I see, so indeed something odd is happening:

 this is how it should look:

(http://i.imgur.com/IF2mfqM.png)

can you confirm that the sample does show this, if you are not sure, make a new fresh project, import the package as is and testify, It's likely something you tweaked inside the fsm that made the string not being updated with the right information.

sorry for the confusion, we'll get to the bottom of this :)

 and yes, you don't have to use gui for this, it was just a straight port from the script you wanted to get in Fsm, I would strongly suggest you use the new UI or something more modern for the UI indeed.



 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 05, 2016, 06:22:32 AM
Hi Jean,

Yes, it does look like the image shown here. When I received the FSM from you I saved it as an original, created a new project and made my tweaks in a new project. I've also been experimenting with the u gui system but that's in a separate project all together and just getting familiar with it.

Come to think of it I did make tweaks to the input but it was just assigning different keys. Other than that, it should be the same.

To review, I show the same which is the output to the screen of "HomeLocation.x = 2". So the player arrives to play the game and the player sees three things:

1. Are you feeling lost?
2. The objective of the game is to find your way home. Go on, you can do it!
3. HomeLocation.x = 2

The 3rd option the player will likely be scratching the head thinking what does that mean?

So, I'm not sure if the best option is just to not show the GUI output to the screen "HomeLocation.x =2". I'm also not sure I really understand it. Is it supposed to output a value in place of the string?

I appreciate your patience. I am in the very beginning stages of trying to understand programming and I can see it will take me quite some time to get the concepts. Thanks!
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on September 06, 2016, 12:03:33 AM
Hi,

 Good.

As for UI, you should get the all the UI samples from the Ecosystem and see how it all fits together. There are some videos explaining the basics too.

all infos and links available on the dedicated wiki page (https://hutonggames.fogbugz.com/default.asp?W1192)

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 22, 2016, 01:25:25 AM
Hi Jean,

I didn't realize that you had replied until now. Sounds good and thank for the tip.

I was mostly just not understanding the reasoning behind displaying HomeLocation.x = 2 to the player. It will probably click at some point so I've moved on to other PlayMaker projects for now to become more familiar.

Thanks,
Dan

Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on September 27, 2016, 11:26:54 PM
Hi,

 Me neither to be honest :) you would either show both or none, but that was how the script was written, so I ported it in PlayMaker as it was. Don't think too much about this for sure.

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 27, 2016, 11:32:11 PM
Ahhh, I see now. Sorry to put you through that. I want to learn PlayMaker but I think I need to set time aside to learn C# too so I pay more attention to what the script is trying to do.
Title: Re: Vector Math Problem[SOLVED]
Post by: jeanfabre on September 28, 2016, 05:00:36 AM
Hi,

 Don't worry :)

You are right, if you know c# and PlayMaker, you'll be in complete control of your Unity projects, and you will be able to achieve anything you want.

 Bye,

 Jean
Title: Re: Vector Math Problem[SOLVED]
Post by: Dan on September 28, 2016, 05:08:31 AM
Sounds good, I will spend most of my time with C# and PlayMaker. Thanks!  :)