playMaker

Author Topic: Frame rate affecting velocities? [SOLVED]  (Read 4286 times)

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
Frame rate affecting velocities? [SOLVED]
« on: June 12, 2013, 07:41:12 PM »
I'm having an odd issue here.  Basically, I'm using a character controller and I'm doing a very simple style of physics calculation for a jump.  The character has no actual gravity, but the character's move variable is set to a vector that is subtracted from every frame until grounded.  That's it. 

The problem arises when the frame rate is not stable at 60fps.  The jump will often times vary heights.  I built out a web builder version and the jump is noticably more floaty than the PC build as if the subtraction is not happening as often as it is supposed to.

This is a very crucial issue as my game demands precise actions every single time moves are performed.  Slight variations (even tiny microscopic ones that can cause things to happen one frame later) will ruin the accuracy I'm going for.

Any idea as to why this is happening?
Any idea as to how to fix it?
« Last Edit: June 19, 2013, 02:55:29 PM by liero116 »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Frame rate affecting velocities?
« Reply #1 on: June 12, 2013, 07:51:54 PM »
Are you running those actions in FixedUpdate?

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.FixedUpdate.html

Standard 'Update' is run every frame, so there is a difference between 30 and 60 fps that affects the calculated result where time is concerned.

'FixedUpdate' is done independent of the framerate so it is consistent.
« Last Edit: June 12, 2013, 07:54:06 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Frame rate affecting velocities?
« Reply #2 on: June 12, 2013, 08:27:02 PM »
Im embarassed to say that I don't actually know.  I'm doing this action through playmaker.  How can I check if I'm doing it there or not?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Frame rate affecting velocities?
« Reply #3 on: June 12, 2013, 09:03:15 PM »
Pfft, dont be embarrassed!

Which actions are you using? Some of them work in FixedUpdate by default, others  don't but often times will have check boxes at the bottom of the action put it in whichever update mode you want.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Frame rate affecting velocities?
« Reply #4 on: June 12, 2013, 09:41:45 PM »
Im using "vector add" or "float add" when necessary, assigning it to another vector and using "controller move" to get them to move.  None of these seem to have a fixed update check box, but I do see "every frame" and "per second" on some of them.  I use every frame most of the time, but could "per second" make a difference?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Frame rate affecting velocities?
« Reply #5 on: June 13, 2013, 01:57:14 PM »
Yes, it will.

It's a little confusing but basically the checkbox for "Every Frame" will do an update every frame. The checkbox for "Per Second" will make it do the action over time. If you check both of them then you should get a repeating action with a static control of the speed irregardless of framerate.

Checking only Per Second will execute it once, so you need Every Frame on to keep it repeating. Try experimenting and seeing how it works out.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

juliocfc

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Frame rate affecting velocities?
« Reply #6 on: June 13, 2013, 07:08:10 PM »
hello I'm from Brazil "google translator kk" ;D

try this

create a global variable called move or any name.
Then create two fsm
"FSM 1" put these actions in this sequence and check all and every frame per second checkbox
State Start
1. "Get Vector3 XYZ" and save the Y
2. "Get Axis Vector" set the multiplier for a variable called speed, set the speed according to your needs - put in Store Vector move global variable and store the magnitude
3. "Vector3 Clamp Magnitude" here put the global variable and set the Max Length variable speed, so when you move the cross there is no speed increase.
4. "Float Subtract" here subtract the variable that you put in Y by gravity that you want.
5. "Set Vector3 XYZ" set the global variable move and place the Y value that was subtracted in y
Move 6.Controller put the global variable here

"FSM 2"
State Start
1. "Controller Is Grounded" here put in a transition Finish true and check every frame
second state
1. "Get Vector3 XYZ" save the Y value of the global variable move
2. "Float Compare" compare the Y value to -1 and set a transition to be less than for the next state and another if less back to the first state. check all every frame.
third state
1. "Set Vector3 XYZ" set the global variable move and place the Y value to -1. not check every frame and place a transition back to the state start
2."Next frame event"

I think this works
« Last Edit: June 13, 2013, 07:09:56 PM by juliocfc »

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Frame rate affecting velocities? [RESOLVED]
« Reply #7 on: June 19, 2013, 02:55:10 PM »
Yes, it will.

It's a little confusing but basically the checkbox for "Every Frame" will do an update every frame. The checkbox for "Per Second" will make it do the action over time. If you check both of them then you should get a repeating action with a static control of the speed irregardless of framerate.

Checking only Per Second will execute it once, so you need Every Frame on to keep it repeating. Try experimenting and seeing how it works out.

I'm about 99% sure this fixed my problem, though some extensive testing will verify this either way.  For now, this is resolved. Thanks!