playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jeanfabre

Pages: 1 ... 986 987 [988] 989 990 ... 997
14806
PlayMaker Help / Re: Playmaker workflow
« on: May 15, 2011, 10:38:06 PM »
Hi,

 no, no. Try to avoid duplicate code and duplicate states or behaviors as much as possible. This is a bad sign. Reusable component and careful crafting of your system is necessary then.

You need to think one level up. Instead of changing states, you deal with several Fsm working at the same time.

 Have one fsm dealing with your character control. On that same gameObject ( makes no difference really), you can add another fsm that control the color animation. And you then send events to this color animator fsm to behave.

 Say your character changes color when jumping ( silly, but you get the point). in your character controller fsm, broadcast a "jump" event when it actually jump.  Your color animator fsm has a global event "jump" that triggers color animation for a given period of time. That's how you achieve simultaneous behaviors without duplicating states. Build an event system around your game that defines entry point or signals for interested parties to act.

Now, how do you trigger that event without loosing the character control. It depends how you have build your controller really. If it's a single Do-it-all state, then you need yet another fsm that will simply respond to the jump input and broadcast a "jump" event. If you move form state to state to control your character then you can add actions or inserts States in your flow to broadcast the "jump" event when appropriate ( character might jump because the ground chaked, not just because the user wanted to)

 If I missed the point, could you elaborate on the behavior you want to achieve: when you want the color to animate, how you want it to stop etc etc.

 Bye,

 Jean

14807
PlayMaker Help / Re: Action for setting value of GUI textfield?
« on: May 15, 2011, 09:43:51 PM »
Hi,

 Yes, if you move to another state then you need to plug it somehow back when you need that behvaior again. But I don't see this as as problem. during the next set of states and action you will perform, you have stored the latest content of that field, so you are ok. Simply reach a state where you again check live for the content when needed.

 ELSE. Make a specific fsm that deals with that gui text field,  sending events when the user presses ok on the form related to this gui text field and react only then.

 Or maybe you could explain the process at stake, maybe it's not conventional or has a twist to it.

 Bye,

 Jean

14808
Hi,

 Ok, don't have time to finish this for today, but try this action. It's dealing with swipe detection, and maintain a value representing the direction and another representing the animation value  ( randing from 0 to 1, proportionnal to the screen width or height depending on the swipe direction).

 Now, that I did all the ground work, I realize that an fsm would have been better, because I can't leave this action or else I loose track of the swipe, so I need to implement some cumbersome events sending to another fsm, not big deal, but did not plan on that on my allocated time...

 So, yes, int this case, an fsm  could makes more sense, because values about the swipe woul dbe maintained and I would evolved within a single fsm between states to then trigger external events as required. But I bet the next versions of playmaker will provide much better UI selectors for events and such and will make this trivial as if I was sending events to the same fsm.

I welcome comments and suggestions on this code, as there are many ways to deal with such behavior and anyway far from complete.

 -- need to expose a lot more settings to tweak the behavior without touching the code.
 -- direction changes not taken in consideration
 -- an absolute vector representing the movement would maybe be useful, or at east easier to handle by other fsm to know what to do

and this doesn't deal with the actual visuals you want to tight to the swipe event, and that is a major part of the work. dealing with knowing where you are, where to go, and all that. But that's already a different aspect of your problem

tested on the device, and it's all smooth,


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.Device)]
[Tooltip("Control and maintain infos about swipe gestures live.")]
public class SwipeLiveGestureEvent : FsmStateAction
{

[Tooltip("How far a touch has to travel to be trigger a swipe action (in pixels)")]
public FsmInt minSwipeTriggerDistance;

[Tooltip("How far a touch has to travel to be considered a valid swipe (e.g. 1 = 1 screen distance on the swipe axis)")]
public FsmFloat minTravelTriggerPercent;
private float minTravelTriggerPixels;

[Tooltip("How fast a touch has to drag to be considered a valid swipe in pixels per seconds")]
public FsmFloat minSpeedTrigger;

[Tooltip("How fast do we animate the swipe when gesture ends")]
public FsmFloat animationSpeed = 10;


[UIHint(UIHint.Variable)]
[Tooltip("Store the swipe direction: none | left | right | up | down")]
public FsmString swipeDirection;

[UIHint(UIHint.Variable)]
[Tooltip("Store the swipe value ranging from 0 to 1")]
public FsmFloat swipeValue;


private bool touchStarted;// has a one-finger-only touch started

private bool swipeStarted; // has the gesture been accepted as a swipe.

private bool swipeCanTrigger; // the swipe gesture is now effective. If true, when gestures end, the swipe will automatically finish


private Vector2 touchStartPos;
private Vector2 swipeDrag;
private enum Direction {none,left,right,up,down};

private Direction _swipeDirection = Direction.none;


private Touch _touch_;


private float animeTarget;
private bool isAnimating;

//float touchStartTime;
public override void Reset()
{
minSwipeTriggerDistance = 2;
minTravelTriggerPercent = 0.5f; // half the screen width or height depending on the swipe direction.
minSpeedTrigger = 100;// in pixels per seconds.

_swipeDirection = Direction.none;

swipeValue = null;
swipeDirection = null;

resetSwipeData();

}

public override void OnEnter()
{
resetSwipeData();
}

public override void OnUpdate()
{

if (isAnimating){
updateTransitionAnimation();
}


// we only deal with one finger touch
if (Input.touchCount != 1)
{
return;
}

_touch_ = Input.touches[0];

switch (_touch_.phase)
{
case TouchPhase.Began:
touchStarted = true;
touchStartPos = _touch_.position;

resetSwipeData();


//touchStartTime = Time.realtimeSinceStartup;

break;

case TouchPhase.Ended:
case TouchPhase.Canceled:

if (touchStarted)
{
// check velocity trigger is distance trigger did not raise
if (!swipeCanTrigger){
float _dragReleaseDeltaMagnitude = _touch_.deltaPosition.magnitude ;
float _dragReleaseDeltaTime = _touch_.deltaTime ;
float _dragReleasespeed = _dragReleaseDeltaMagnitude*_dragReleaseDeltaTime;
Debug.Log("The user swipe released at speed"+_dragReleasespeed);

if (_dragReleasespeed>minSpeedTrigger.Value){
Debug.Log("we accept the swipe speed wise");
swipeCanTrigger= true;
}
}

triggerTransitionAnimation();
touchStarted = false;
}

break;

case TouchPhase.Moved:

// compute the drag vector
swipeDrag =  _touch_.position - touchStartPos ;

// detect when the gesture is considered a swipe
if (!swipeStarted){
// check the direction and validate the minimal distance to initiate ( not necessarly validate) a swipe gesture
if ( Mathf.Abs(swipeDrag.x) > Mathf.Abs(swipeDrag.y) && Mathf.Abs(swipeDrag.x) >= minSwipeTriggerDistance.Value  ){

swipeStarted = true;

// we go horizontaly, yes, but in what direction
_swipeDirection = swipeDrag.x<0 ? Direction.right:Direction.left;

swipeDirection.Value = _swipeDirection.ToString();

minTravelTriggerPixels = Screen.width*minTravelTriggerPercent.Value;

}else if ( Mathf.Abs(swipeDrag.x) < Mathf.Abs(swipeDrag.y) && Mathf.Abs(swipeDrag.y)>=minSwipeTriggerDistance.Value ){
swipeStarted = true;

// we go verticaly, yes, but in what direction
_swipeDirection = swipeDrag.y<0 ? Direction.up:Direction.down;

swipeDirection.Value = _swipeDirection.ToString();

minTravelTriggerPixels = Screen.height*minTravelTriggerPercent.Value;

}
}


// !swipeStarted and swipeStart check are not tight in with an "else" so that the swipeValue is straight away computed and avoid latency.
if (swipeStarted){

// let's update the swipe value
if (_swipeDirection == Direction.right || _swipeDirection == Direction.left){
swipeValue.Value = Mathf.Abs(swipeDrag.x)/Screen.width;
if (!swipeCanTrigger){
if ( Mathf.Abs(swipeDrag.x) > minTravelTriggerPixels  ){
swipeCanTrigger = true;
}
}

}else if ( _swipeDirection == Direction.up || _swipeDirection == Direction.down) {
swipeValue.Value = Mathf.Abs(swipeDrag.y)/Screen.height;
if (!swipeCanTrigger){
if ( Mathf.Abs(swipeDrag.y) > minTravelTriggerPixels  ){
swipeCanTrigger = true;
}
}

}

// also we check user input for clues like drag distance
// and decide on the gesture validity.

}

break;
}
}




private void triggerTransitionAnimation(){
if (swipeCanTrigger){
animeTarget = 1f;
isAnimating = true;

}else{
// we animate back
animeTarget = 0f;
isAnimating = true;
}
}// animateTransition



private void updateTransitionAnimation(){


// TODO: make it with iTween or EZGUI tweening system for more flexibilities.
swipeValue.Value = Mathf.Lerp(swipeValue.Value,animeTarget,animationSpeed.Value*Time.deltaTime);

// check if we have finished our animation
// check can be improved, but will do for now
if ( Mathf.Abs(swipeValue.Value-animeTarget)<0.001  ){
swipeValue.Value = animeTarget;

// WE ARE DONE WITH MOVING
isAnimating = false;
_swipeDirection = Direction.none;

resetSwipeData();

}// we have finished animating
}// _updateTransitionAnimation

private void resetSwipeData(){

if (swipeDirection != null){
swipeDirection.Value = _swipeDirection.ToString();
}

swipeCanTrigger = false;
swipeStarted = false;
swipeDrag = Vector2.zero;
if (swipeValue != null){
swipeValue.Value = 0f;
}

}


/*
void TestForSwipeGesture(Touch touch)
{
// test min distance

var lastPos = touch.position;
var distance = Vector2.Distance(lastPos, touchStartPos);

if (distance > minSwipeDistancePixels)
{
float dy = lastPos.y - touchStartPos.y;
float dx = lastPos.x - touchStartPos.x;

float angle = Mathf.Rad2Deg * Mathf.Atan2(dx, dy);

angle = (360 + angle - 45) % 360;

Debug.Log (angle);

if (angle < 90)
{
Fsm.Event(swipeRightEvent);
}
else if (angle < 180)
{
Fsm.Event(swipeDownEvent);
}
else if (angle < 270)
{
Fsm.Event(swipeLeftEvent);
}
else
{
Fsm.Event(swipeUpEvent);
}
}
}
*/
}
}



 Bye,

 Jean

14809
PlayMaker Bug Reporting / / char in fsm component names
« on: May 13, 2011, 12:45:13 AM »
Hi,

 Funny quirk or useful feature?

If you name a fsm component  hello/me/again it will create  sub menus in the dropdown list of fsm  in the editor.

It's actually quite cool when you think about it, but just wanted to make sure you were aware of this and either make it as a feature, document it or fix it. Not at all critical obviously.

 Bye,

 Jean

14810
PlayMaker Help / Re: Search arrays?
« on: May 12, 2011, 10:50:49 PM »
Hi,

 Can you share the script, and I'll have a look ? cheers.

 Bye,

 Jean

14811
PlayMaker Help / Re: PlayAnimation finished event
« on: May 12, 2011, 10:26:38 PM »
Exactly, so all in all, down the road as your project grows, you will likely find that controlling anims with time is needed.

 Bye,

 Jean

14812
PlayMaker Help / Re: Search arrays?
« on: May 12, 2011, 10:24:53 PM »
Hi,

 I think you have to run it as a c# script, is it so or have tried to convert it and run it as a javascript?

 Bye,

 Jean

14813
Action Requests / Re: Sequencing actions
« on: May 12, 2011, 10:23:32 PM »
Hi,

 Hierarchical FSM : http://aigamedev.com/open/articles/hfsm-gist/, that's what we were trying to define with these sub fsm and grouping stuff. Thanks for pointing that out!

I currently can achieve quite complex AI because I cut down the problem into several fsm and give them enough info and events so that they know when to act, and yes, If I could have some kind of HFSM, It would improve the flow and power of the behavior and would be a lot easier to develop, maintain and expand.

 HFSM pretty please Alex :)

 Bye,

 Jean

14814
Hi Peter,

 I have implemented such live swipe but it's all scripted at the moment ( done before the Playmaker era :) ), so I have the logic but not done in Playmaker.

How do you expect the swipe to behave when the user releases the touch? currently I detect swipe speed and travel and validate the swipe based on these two params so that the swipe lands naturally on  the new content or back if speed or travel is sufficient. Or do you simply need some kind of scrolling? How do you want the scrolling or swiping limits to behave? with elasticity or with hard bounds?

Also, how do you expect the swipe value to range from and to and compare to what? Do you want to swipe the screen or a gui component or part of the screen?

I am currently unsure if it actually should be done in Playmaker or as an action. As an exercice, yes, but in a real world project, I would suspect such system  to be a lot easier to implement and reuse properly as an action, at least until sub fsm is out, tho a template could be used.

Allow me few days to get back to you with at least a basic action or fsm.


 Bye,

 Jean

14815
PlayMaker Help / Re: PlayAnimation finished event
« on: May 11, 2011, 10:31:15 PM »
Hi,

 I found much easier to manually deal with the animation time. Some more info : http://hutonggames.com/playmakerforum/index.php?topic=169.0

 Bye,

 Jean

14816
Hi,

Confused now. You are right, my playmaker dll disappeared and the fsmStateAction was missing somehow, I just can't explain why it disappeared. I have reimported playmaker and now everything is back including the previously faulty imported package.

 Trying to replicate. But now all is fine, can't replicate this again.

 Bye,

 Jean

14817
PlayMaker Help / Re: how to get FSM to export with object?
« on: May 11, 2011, 10:05:59 AM »
WOoo

Ok, I can replicate this, I assumed something simple was the source of your issue, but I experience the same thing.

 I have filed that as a bug on the other forum : http://hutonggames.com/playmakerforum/index.php?topic=245.0

Bye,

 Jean

14818
Hi,

 Thanks to hairyMug for his finding ( http://hutonggames.com/playmakerforum/index.php?topic=244.0 ), I think we have an issue with exporting a gameobject with a fsm component in a package. when importing back, the component is missing the reference to the script. I think simply because there isn't ( if you switch to debug, you'll get a white content in place of the script reference).

 So this is something you are aware of Alex right? maybe I missed it in the doc.

 Bye,

 Jean

14819
PlayMaker Help / Re: ControllerSimpleMove color stairs question
« on: May 11, 2011, 07:26:35 AM »
Hi,

 Try few things:

Maybe you are setting the alpha to 0 and therefore the model becomes invisible.
Maybe you move the model and becomes out of view or in the wrong place.

Is it happening during the game place or when you actually do something when editing?

 Bye,

 jean

14820
PlayMaker Help / Re: how to get FSM to export with object?
« on: May 11, 2011, 07:23:52 AM »
Hi,

Try this: make sure you Select dependencies when you export a package. Select your gameObject, then go into the menu "Assets" and click "Select dependancies"

 This might be the reason why.

Bye,

 Jean


Pages: 1 ... 986 987 [988] 989 990 ... 997