playMaker

Author Topic: Get Button doesn't work?[SOLVED]  (Read 3056 times)

MurDocINC

  • Playmaker Newbie
  • *
  • Posts: 8
Get Button doesn't work?[SOLVED]
« on: April 14, 2013, 01:41:57 PM »
For some reason I can't get "Get Button" to detect "Fire1", mouse or keyboard. My stored variable always returns false. "Get Button Down" detects it but that's not what I'm after, I need the "hold" functionality.
Why isn't it working?!
« Last Edit: April 14, 2013, 09:23:02 PM by MurDocINC »

MurDocINC

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Get Button doesn't work?
« Reply #1 on: April 14, 2013, 07:25:53 PM »
Dunno what I did but it's working now. But now I need help with my logic.
What I'm trying to do:
Code: [Select]
function Update()
{
if (Input.GetButton("Fire1"))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast(ray, hit))
{
transform.position = hit.point;
}
}
}
My FSM:
Listener state - Get button, store it in bool. "bool all true" to send event.
Holding state- Mouse pick, store vector. Set position to stored vector...?

Don't know how to continue my loop so it keeps moving my cube while I hold down my button. I try few ways but they either didn't continue or I got loop limit error. Help please.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Get Button doesn't work?
« Reply #2 on: April 14, 2013, 07:32:24 PM »
I would use 2 states:

Idle - waits for Get Button Down (or whatever starts the move)
MoveTo - raycast, move etc. transitions back to Idle on Get Button Up (or end condition)

Not at my computer, but I believe there's also a sample that does this (maybe in TestLab/Input)

MurDocINC

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Get Button doesn't work?
« Reply #3 on: April 14, 2013, 08:07:15 PM »
Yes that worked, just had to check "every frame" for raycast and move, to get the result I want. A little different logic than the script, as states have their own update.
Anyways thanks!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Get Button doesn't work?[SOLVED]
« Reply #4 on: April 14, 2013, 10:30:08 PM »
Cool. I wouldn't take a script too literally when trying to convert it to Playmaker. Instead I would break the behavior down into states first. The result is generally better than the script! It's easier to debug, you can send events to other FSMs at the appropriate times, and it's much easier to change the behavior by adding new states...