playMaker

Author Topic: Vector Math Problem[SOLVED]  (Read 5058 times)

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Vector Math Problem[SOLVED]
« 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.

« Last Edit: August 17, 2016, 03:52:43 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem
« Reply #1 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

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem
« Reply #2 on: August 11, 2016, 10:54:27 AM »
Very cool, thanks!   :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem
« Reply #3 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



Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem
« Reply #4 on: August 17, 2016, 02:11:52 AM »
This has helped a lot! I really appreciate it. Thanks!

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #5 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?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem[SOLVED]
« Reply #6 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


Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #7 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem[SOLVED]
« Reply #8 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

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #9 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem[SOLVED]
« Reply #10 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

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #11 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Vector Math Problem[SOLVED]
« Reply #12 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

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #13 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.

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?


Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
    • Personal Site
Re: Vector Math Problem[SOLVED]
« Reply #14 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.