playMaker

Author Topic: 【Thanks.Resolved】Please teach me how to quicken processing.  (Read 3069 times)

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Hello,I have a anxiety.
Please teach me about FSM.

First image I uploaded is Overall picture of FSM  to control 2Dcharacter.
But I think this FSM has too many states.
Because it's processing is so slow.
I feel delay in Input,to be precise.
In fact it was confirmed in GameWindow .

In conclusion,I want to knom why FSM work slowly.

This FSM enabled character to do some actions 『idle』『Rolling(In other words "avoid")』『left and right moving』『jump』『move while jumping』『Squat』『Move while Squating』『Dash』.
And I use one more FSM to detect ground by trigger event.

I mainly use 『Get Axis』『set float value』『Set Bool Value』『Float Multiply』『Set velocity』『Conditional Expression』『set layer』 in image's FSM.
Please look at other three images.
It's processing to go right.
If you’d like, check content of processing.

My English is too poor.
If you feel rude or confusion,I sincerely apologize.

And my images contain some Japanese.
If they interrupt you,I also apologize for that.

To supplement,my PC has 16GB RAM and 512GB SSD and intel core5 4200M CPU.
Also it has no Graphic board.
Could it be lack of Machine performance?
« Last Edit: May 10, 2020, 01:01:36 AM by zabuton »

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #1 on: May 05, 2020, 10:39:58 AM »
At last,please have a look at aditional image.
It's my Input setting.
"Horizontal" is use for move.
 I hope this helps for answering, but please let me know if you need anything else or if you have any other questions.
« Last Edit: May 05, 2020, 10:49:00 AM by zabuton »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Please teach me how to quicken processing.
« Reply #2 on: May 05, 2020, 12:55:33 PM »
Hi, you probably want to split this up into multiple fsms.

for example 1 for axis and movement 1 for buttons pressed for jump , roll etc

Even those maybe better to split up (depending on your game) , but then you need to build a system the disable each part.

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Please teach me how to quicken processing.
« Reply #3 on: May 05, 2020, 12:58:42 PM »
1. I'm not sure about the performance, even if it does, it is probably related to unity itself. Have you tried Unity Demo 2d games and see if it is laggy?

2. Regarding your FSM design, it is so complicated, don't try to fit everything in one FSM

3. Use couple FSM that runs simultaneously, for example, movement and jump can be separated

4. I Recommend making boolean to serve as your current state/flag.

For example,

a. Ground Check, make a ground check by using raycast2d to the ground and create a boolean variable with a name like : isGrounded whenever raycast hit set isGrounded to true

b. Make another state for horizontal movement, and make a boolean flag isMoving to true if character move. and set it to false when velocityX is 0.

c. make another flag for : isJumping, isAttacking, isDucking, isDashing, isFlipping,etc etc

d. if you do things right, you should have a bunch of flags boolean variable. You use this to control what is allowed and what isn't

for example, Jump, it will probably goes like this
Wait For Spacebar > "Check Conditions" > Jump
where "Check Conditions" could be
  isGrounded = True (Obviously you need to be grounded before you can jump)
  isDash = False (Normally you can't jump during dash)
  isGotHit = False (You probably can't jump when you got hit)
If above conditions are met, then you send it to Jump state, otherwise you'll return to Wait For SpaceBar State.

There's much more, but it is the fun part

Cheers

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #4 on: May 05, 2020, 02:02:23 PM »
To Mr.ch1ky3n

Thank you for reply.
I'm too fool.So I Worried for a long time  to understand your advice.
But thank to your kind rewriting and Mr.djaydino's post,now I understand it.

Sumally,I should make some FSM.
And set enough booleans which were made as globl variable.
I think this way will reduce number of times FSM's processing.
FSM which I made is too complexity.
So it need five processing to move from idle state to dash state .
It's natural that so slowly.

Then Demo 2d games worked Without problem.
So this problem because of my design.

I want to put you and Mr.djaydino's advice in action.
But It's 3 o'clock in the morning Jpan...
So I will carry out it tomorrow soon.

Thanks again.

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #5 on: May 05, 2020, 02:15:30 PM »
To Mr.djaydino

Thank you for your reply.
Your advice is so easy to understand and useful.
In addition, your advice also helped me to under stand Mr.ch1ky3n's great advice.
Without you two, I couldn't understand good way to make FSM.

I thank all of you from my heart for your cooperation.

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #6 on: May 06, 2020, 05:55:32 AM »
 Sorry,please help me.
I made three FSM.
And I assigned processes like three images I uploaded.
But delay of input wasn't improved.

First image's FSM handle processing of some state's horizontal move.
Other FSM send to this FSM boolean.
And it decide moving speed according to their.

Second image's FSM handle processing of "Avoid and it's boolean" and "Dash's boolean"
Third image's FSM handle processing of "Squat and it's boolean" and "Jump and it's boolean" .

Please teach me, what is wrong.
And I'm sorry many times.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Please teach me how to quicken processing.
« Reply #7 on: May 06, 2020, 02:15:39 PM »
Hi.
You might want to look to your input settings, especially to gravity and sensitivity.

Also maybe you can show the actions you are using.

Which parts are working slowly?

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Please teach me how to quicken processing.
« Reply #8 on: May 06, 2020, 02:22:51 PM »
Also, you might want to do just horizontal movement and see if it is laggy?

please show us your
Rigidbody2d component parameters
Pixel per unit settings at your asset/sprite/Your Player Sprite
Physics2D settings at edit>Project Settings>Physic2D
Input Settings at edit>Project Settings>Input> Horizontal

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #9 on: May 06, 2020, 03:17:27 PM »
To Mr.djaydino

Thanks for your repling.
This Image is input's setting.
And all of the states are delayed.
If I press ke,it's reaction is delayed or in spite of release the key character keep move.
I saw horizontal's value keeping "1" , after I released key.
This problem happens everywhere .

Thank you for spending time for me.
But if it’s okay,please help me a little more.
« Last Edit: May 06, 2020, 03:52:38 PM by zabuton »

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #10 on: May 06, 2020, 03:42:13 PM »
Thank you for your response.

I see delay in neutral horizontal move.
When I put key, character didn't move soon.
And when I released key, character didn't stop soon.
About the latter,horizontal key's value kept "1" even after releasing key.

Then I upload three images  following your kind advice.
Please tell me if there is a mistake.

I'm sorry for the trouble but thank you for your cooperation.
« Last Edit: May 06, 2020, 03:46:18 PM by zabuton »

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Please teach me how to quicken processing.
« Reply #11 on: May 06, 2020, 11:31:05 PM »
pls show us your state that contains

1. Get Axis for your horizontal movement
2. How you apply the velocity
3. How and what conditions to stop velocity

« Last Edit: May 06, 2020, 11:39:03 PM by ch1ky3n »

zabuton

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Please teach me how to quicken processing.
« Reply #12 on: May 07, 2020, 12:33:44 AM »
Sorry!
I was misunderstanding.
I will answer again.

1. Yes, I use "Get Axis" action.
2.I use "Set Velocity" action.But I can not explain it's details well in English.
So I upload"right move" state's image.
Sorry to trouble you, but please confirm.

3.If isDash,isJump etc... other state's boolean is true or character face reverse direction,Conditional expression send event to finish "Move states".
Then next state reset velocity and judge which way character face.
And state after next judge boolean.
Also about it I upload images.


 Did I answer properly?
I apologize for the inconvenience this may cause.
« Last Edit: May 07, 2020, 12:57:46 AM by zabuton »

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Please teach me how to quicken processing.
« Reply #13 on: May 07, 2020, 04:25:00 PM »
This is far from perfect, but pls try it and see if it is run smoothly

Tab = Dash
Space= jump

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Please teach me how to quicken processing.
« Reply #14 on: May 07, 2020, 07:58:30 PM »
Incidentally, I also found PlayMaker (which I love) to be not so good for core mechanics of a platformer. It works somewhat for a simple design. Days ago, I finally caved and implemented a player controller with a c# script, but also compared it to an identical FSM. The PM one really did lag behind a bit.

Hello Zabuton,

1) Look for GetAxisRaw to get the axis. This is more responsive.

2) Set Velocity causes trouble when you want to use physics, because it overrides the velocity physics forces. Use Add Force, set it high and cap (clamp) the velocity value to the max speed. This also feels better, however I do not know if there is a clamp velocity in the ecosystem. Below is a simpler version.
 
3) For a start, use one FSM for each mechanic. Movement and flip can be one FSM at first. Here’s a simple setup, out of the top of my mind.

MOVE
Move Right
FloatCompare (if axis < -0.1 Go to Move Left state)
GetAxisRaw
SetVelocity
Once: set scale X = 1

Move Left
FloatCompare (if axis > 0.1 Go to Move Right state)
GetAxisRaw
SetVelocity
Once: set scale X = -1

JUMP
Watch
GetButtonDown (go to check)

Check
Get FSM bool onGround (from Senses), if true, jump

Do Jump
Add Force up

SENSES
Watch
Cast one or several rays down.
If Any True (then onGround = true)

And so on. I recommend to start simple, get it working. And as needed, add complexity. If anything gets too big, simply put it into another FSM.

Look into send event, and get fsm or set fsm variables to communicate between FSMs and good luck.  :)

« Last Edit: May 08, 2020, 05:09:42 AM by Thore »