playMaker

Author Topic: How to campare variables?  (Read 5166 times)

ryf9059

  • Full Member
  • ***
  • Posts: 100
How to campare variables?
« on: June 03, 2013, 12:38:36 PM »
I want to be able to switch state based on different variables, for example, get Axis returns a float, I want to decide to turn right or left based on this value and hence enter different state.

How is this achieved?

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: How to campare variables?
« Reply #1 on: June 03, 2013, 12:45:50 PM »
Hello,

You can try the "Float Compare" action where it compares two floats according to value where you will have an option to flow from the state that has the "Float Compare" action into 3 other states according to the comparison (less, more than or equal to).

Hope that helps.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to campare variables?
« Reply #2 on: June 03, 2013, 01:13:50 PM »
If you are using Get Axis and there is an idle state it will consider 0 (which it always rolls back to) to be a positive number, so you will always be throwing the positive direction trigger while not pressing a direction for the axis.

To fix it, when you throw the trigger to go to the negative direction just use a Float Add in that state and subtract -0.1 (or something tiny) from the axis value so it stays negative. Its a local change so it isnt affecting the actual axis and when the player presses the key it will immediately update to its (mostly) correct value.

If you are using a rotation then it will be in the form of 0 - 360 on the degree's table which is weird to convert, in the same state direction system I just subtract 360 on the negative side so it is always relative to 0 and either positive or negative instead of in actual world degrees.

Images below explain how it works. My 2d Side Scroller example and another thread called "Rotation woes" I made have scenes with FSM's for this if you need to look at them.

Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: How to campare variables?
« Reply #3 on: June 03, 2013, 01:19:46 PM »
If you are using Get Axis and there is an idle state it will consider 0 (which it always rolls back to) to be a positive number, so you will always be throwing the positive direction trigger while not pressing a direction for the axis.

To fix it, when you throw the trigger to go to the negative direction just use a Float Add in that state and subtract -0.1 (or something tiny) from the axis value so it stays negative. Its a local change so it isnt affecting the actual axis and when the player presses the key it will immediately update to its (mostly) correct value.

If you are using a rotation then it will be in the form of 0 - 360 on the degree's table which is weird to convert, in the same state direction system I just subtract 360 on the negative side so it is always relative to 0 and either positive or negative instead of in actual world degrees.

Images below explain how it works. My 2d Side Scroller example and another thread called "Rotation woes" I made have scenes with FSM's for this if you need to look at them.


Thanks! But where can I find the compare and arithmetic (addition, subtraction, etc) action from the action browser?

Oh and yes, please send me a link to the 2D side scroller example. Besides that I also need to dig a little bit on controller and camera. Which is mentioned in my last post about custom scripting (you said you are going to make an example that covers my issue).
« Last Edit: June 03, 2013, 01:24:51 PM by ryf9059 »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to campare variables?
« Reply #4 on: June 03, 2013, 01:24:01 PM »
At the top of the action browser there is a search function you can use.

Generally, I just double click the empty space in the state's action area, then start typing the name of what I want and it filters actively while you type so there are several results. You could just type "compare" and its giving you everything for compare's.

Otherwise, its under Math, i believe.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: How to campare variables?
« Reply #5 on: June 03, 2013, 01:27:17 PM »
At the top of the action browser there is a search function you can use.

Generally, I just double click the empty space in the state's action area, then start typing the name of what I want and it filters actively while you type so there are several results. You could just type "compare" and its giving you everything for compare's.

Otherwise, its under Math, i believe.


And please send me a link to the 2D side scroller example. Besides that I also need to dig a little bit on controller and camera. Which is mentioned in my last post about custom scripting (you said you are going to make an example that covers my issue).

Thanks again!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to campare variables?
« Reply #6 on: June 03, 2013, 01:30:36 PM »
It's in progress, but may be enough to suit your needs. I'll continue to update it until I think it's good enough to be a proper, bug free, working template.

http://hutonggames.com/playmakerforum/index.php?topic=4025.0


I've been thinking about the camera trailing you posted about, but haven't had time to look into it.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: How to campare variables?
« Reply #7 on: June 03, 2013, 01:35:28 PM »
It's in progress, but may be enough to suit your needs. I'll continue to update it until I think it's good enough to be a proper, bug free, working template.

http://hutonggames.com/playmakerforum/index.php?topic=4025.0


I've been thinking about the camera trailing you posted about, but haven't had time to look into it.


I suggest making a tutorial series on 2D game setup (cameras and stuff), I also watched those on youtube but they are more for like board games.

Since there are a lot of people making 2D games and that might come in handy :)

EDIT: For the camera now I'm able to use it to follow the player just by using translation. But I want to achieve some more advanced effect like damping (inertia), and giving more space based on the direction the player is faced (for example, if facing left, then camera moves to the left so player is at the right of the camera so there are more space to see on the left, and vice versa).

Is that achievable?
« Last Edit: June 03, 2013, 01:39:13 PM by ryf9059 »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to campare variables?
« Reply #8 on: June 03, 2013, 01:51:12 PM »
I currently have that in the scroller example. Take a look.

2d games are principally the same as 3d but you just change the camera to orthographic projection and only look straight down one axis so it flattens everything out. Most people use toolkits from the asset store to handle the sprites & animations. I don't have any of them so it is simpler for me to make a flat-style 3d example and let the end user integrate their kit if they want to use one.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: How to campare variables?
« Reply #9 on: June 03, 2013, 02:11:14 PM »
I currently have that in the scroller example. Take a look.

2d games are principally the same as 3d but you just change the camera to orthographic projection and only look straight down one axis so it flattens everything out. Most people use toolkits from the asset store to handle the sprites & animations. I don't have any of them so it is simpler for me to make a flat-style 3d example and let the end user integrate their kit if they want to use one.


I saw your example, it's simply using smooth follow action.

With that, seems I don't have too much flexibility on adjusting the camera. For example, how many space can have while facing one direction, the offset for the camera (crucial), etc. Also, when the player jumps the camera tilt, if using ortho camera the effect is serious that can break the game visual. I also cannot determine how much space there should be when jumping. Basically, I have no control over it, and I tried it on my game already and it turns out undesirable :(

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to campare variables?
« Reply #10 on: June 03, 2013, 02:19:53 PM »
I saw your example, it's simply using smooth follow action.

It works for the application I'm using it for, but I'll look into an ortho version.

Quote
With that, seems I don't have too much flexibility on adjusting the camera. For example, how many space can have while facing one direction, the offset for the camera (crucial), etc. Also, when the player jumps the camera tilt, if using ortho camera the effect is serious that can break the game visual. I also cannot determine how much space there should be when jumping. Basically, I have no control over it, and I tried it on my game already and it turns out undesirable :(

Those are all adjustable. If they weren't adjustable, they wouldn't exist as they are in the first place.

Smooth Follow exposes the follow distance, height and dampening to restrict rotation.

The jumps are controlled by Force. If you want to jump higher then just increase the force.

The camera flipping is exposed in the Look Direction FSM and is tween'd to a new location. Change the tween coordinates to alter where it moves to in relation to the character.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: How to campare variables?
« Reply #11 on: June 03, 2013, 03:03:33 PM »

Those are all adjustable. If they weren't adjustable, they wouldn't exist as they are in the first place.

Smooth Follow exposes the follow distance, height and dampening to restrict rotation.

The jumps are controlled by Force. If you want to jump higher then just increase the force.

The camera flipping is exposed in the Look Direction FSM and is tween'd to a new location. Change the tween coordinates to alter where it moves to in relation to the character.

Ah, there are more than one FSM? I will be more careful and look into it.

But still I didn't see how can I adjust offset of this camera, currently in my project the player is at a way-too-top posision and I want to move it above in general

Is this also in the Look Direction FSM?