playMaker

Author Topic: Is there a way to limit the FPS?  (Read 4048 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Is there a way to limit the FPS?
« on: August 10, 2014, 03:40:13 PM »
I know it seems like a really odd question but I've been working on the side-scroller and since it's using the every-frame to calculate the gravity that I'm trying to apply to the character, if the frame rate of how fast the "Every frame" fires off is different that's going to result in differences and variances...

And I also know that making it use my own custom gravity system is a little out there, it's because I just wasn't satisfied with the engine-specific gravity (too floaty... Even with the mass and other calculations changed/adjusted.)

So, is there a way to limit the every frame by limiting the FPS or something? I need it to be precise (or would this be where the "Fixed update" option for every frame executions would be a better solution?)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Is there a way to limit the FPS?
« Reply #1 on: August 11, 2014, 10:14:56 AM »
ouch...

 This is a very usual sympton, and I strongly think that this is only going to make it worse...

 you have an action to constraint frame rate yes:

http://hutonggames.com/playmakerforum/index.php?topic=2424.msg38496#msg38496

I did make a post on the rss feed. so you should watch that rss feed for the latest ( you can also opt as with your emil to get emailed when new rss entries arrives. you can download that action using the ecosystem as well.


ok, now back to why I think this is a bad idea.

if your physics is too floaty, it's because you likely want to tweak the forces, weights, drags and most likely the time and physics settings themselves. Have you tried for example to increase the solver iteration count of the Unity physics settings? this is definitly stiffening your simulation.

AND, constraining the framerate may not even give any changes in the physics simulation at all, since the physics engine runs on a separate system ( hence why there is these various FixedUpdate, LateUpdate and Update calls every frame).

So, I would definitly try to sanitize your scene and objects before building your own gravity system, especially if it's not a twisted one like spherical gravity or walls graivts, etc.

 Bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Is there a way to limit the FPS?
« Reply #2 on: August 11, 2014, 11:21:38 AM »
It's not uncommon to fake the physics, SMB is almost entirely faked and feels very fluid. But... Keep in mind that it is definitely not the easy path.

If you need things to be framerate independent then you need to call them on FixedUpdate.

http://unity3d.com/learn/tutorials/modules/beginner/scripting/update-and-fixedupdate

You can also adjust physics settings at Edit>Project Settings>Physics... Also you can change the timestep at Edit>Project Settings>Time... But I wouldn't recommend messing with that.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Is there a way to limit the FPS?
« Reply #3 on: August 12, 2014, 03:20:38 PM »
Jean: Yeah, I know it's a dirty method... And I'm going to guess that using the actual in-engine physics would be far cleaner... But I just can't really get it to work the way I want it to. The reason is because I wanted to make one of those variable jumping mechanics so the user can jump either really high or not very high depending on how long they hold the jump button... With the physics system itself, getting that done is really tricky if not nightmare-level finicky. And that's not even getting into controlling a jump mid-air (and keeping the controls nice and tight/responsive.)

Essentially, I'm trying to do my best to emulate the functionality of Super Mario World... And as much as the physics engine in Unity is nice, it's not always the best solution for every approach.

Lane: Yeah, I'm sure if I was able to tell the actions that do all this to use the fixed update instead of the regular update that'd keep things cleaner because afaik the fixed-update is at explicitly regular intervals that are independent of the computer's ability to do stuff... So, if I had the ability to tell the actions to use the fixed update functions instead of the regular update function I suspect that'd allow me to keep this clean and consistent across different platforms.
« Last Edit: August 12, 2014, 03:22:33 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Is there a way to limit the FPS?
« Reply #4 on: August 12, 2014, 06:48:52 PM »
I know that it's not something I'm really able to parse very well given I'm not a coder at heart... But I took a look into the set velocity action code and I don't see any update function in there (at least not that I can tell...)

Is it safe to assume that the connection between these sorts of actions and PlayMaker's connection to the physics systems is shrouded in some way?

That all being said, I am curious... Because since it seems to be reaching into the physics itself (as best as I can tell) then is it safe to assume that this would be unaffected by any FPS differences? Reason I ask is that when I poked my nose into the set-velocity code it seems to be connected straight up to the physics so given that I'm wondering if needing a way to limit the FPS or soaking the CPU cycles down would even be worthwhile...

... and yeah, I am going to see about doing what I can to understand C#. I get the feeling if I understood it a little better I'd be able to answer 90% of the questions I find myself asking :lol:

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Is there a way to limit the FPS?
« Reply #5 on: August 12, 2014, 08:19:04 PM »
The code isn't shrouded, the Set Velocity action has a OnFixedUpdate. It's the same as OnUpdate but on a fixed timestep.

Looking over these will help, as well as the link above for the update/fixedupdate thing from Unity.
https://hutonggames.fogbugz.com/default.asp?W127
https://hutonggames.fogbugz.com/default.asp?W166

Coding custom actions is fairly straightforward, really. You do all of the normal code you would if you were writing a regular script basically just with the exception of some replacement functions for PM, so the entire Unity API still applies. The biggest thing that might be confusing is that all of the FsmVariables are not the same as regular variables and you have to use the .Value property to access them with normal variables.

It takes some mucking around if you haven't done any fundamental programming classes or anything... I had a hard time getting started and kinda wish I would just sit down and do some more fundamental research to understand the formatting principles and basic language structure altogether. Basically I just looked at existing actions and by copy-pasting finally found out what worked and didn't work.. Now I peruse the Scripting Reference and figure out all the weird stuff on msdn, Unity Answers or google (which normally turns up stackexchange stuff i have a hard time understanding..).

Just takes patience... Not everything is as easy as Playmaker =)
« Last Edit: August 12, 2014, 08:21:29 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Is there a way to limit the FPS?
« Reply #6 on: August 12, 2014, 09:54:25 PM »
True there... That said, I've been told that since I have the head for maxscripting (the internal language of 3ds max used for some of the more advanced rigging techniques) that I may have the head for programming in C since they have a lot of common structures and such.  So that is why I think it is about time I try to learn it.

Not that I would be abandoning PlayMaker, though... I mean I still like using it as it is way easier to debug and such... But it might help me to gain a better understanding if I can broaden my knowledge like that.

As for the set velocity using the fixed update... That does make me wonder if I should be as worried as I am about peformance of the systems I have made up... If the system is already running in a uniform and reliably consistent manner, that does suggest that on older devices that the framerate or other slowdowns may not actually hamper the performance or make the responsiveness lag (well, it would if it is on a first-gen iPhone but I hope you get what I'm sayng here. ;) ) Because I am quite sure that if SMW were laggy or slow it likely wouldnt have become such an iconic game to start with.