playMaker

Author Topic: SetVelocity with fixed update  (Read 404 times)

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
SetVelocity with fixed update
« on: June 11, 2018, 09:27:33 AM »
I move my objects in my game using SetVelocity and I ending up with this problem that they move inconsistent depending on frame rate.

From reading a bit it looks like I want to move them in fixed update so I wonder if there is a SetVelocity action that uses fixed update?

Is this the right way or am I misunderstanding things? I try to use as little as possible of Unitys gravity since it's impossible to get the precision I need for jump height and such.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: SetVelocity with fixed update
« Reply #1 on: June 12, 2018, 01:22:03 AM »
Hi.
The set velocity works in fixed update :)

So there might be something else going on, maybe drag?

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #2 on: June 12, 2018, 05:24:36 AM »
Nah, that's not it. Even when I change time scale I get completely different jump heights and speed. It's like Unity tries to make everything move at the same speed through frame skips rather than slowdowns.

Here is an old thread with the same issue and it looks like no answer was found.
http://hutonggames.com/playmakerforum/index.php?topic=8097.0

I've tried a frame limiter but it's inconsistent too and the problems really starts if the frame rate drops below 60. That's why I wondered if SetVelocity used fixed, because it's not acting as it should.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: SetVelocity with fixed update
« Reply #3 on: June 12, 2018, 07:48:02 AM »
Hi.
You can open the action script by right-clicking the action and select edit script.

in the action you will see this part :
Code: [Select]
public override void OnFixedUpdate()
{
DoSetVelocity();

if (!everyFrame)
Finish();
}

Which means that it runs on fixed update :)

So there must be some other issues.

I check on the unity forums and actually many people have issues with that

I did a bit of testing and when i use an 'add force' and force Mode set to 'impulse'

it seems to be consistence.

Maybe you can show your setup?

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #4 on: June 12, 2018, 09:46:21 AM »
I could show, maybe. I don't know how to in a comprehensible way though. Lots of states in different FSMs.

Add force or translate does the same thing so that's not it.

But it's not just jump height that gets screwy. Hit detection stops working too. It's like Unity skips frames and I don't want that. That's why I asked about fixed update.

I'm not sure what to do now.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: SetVelocity with fixed update
« Reply #5 on: June 12, 2018, 12:45:17 PM »
Hi,
Have you tried in a build?

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #6 on: June 12, 2018, 02:12:45 PM »
No, it runs fine when it's 60fps and since I have no way to tank the fps outside of the editor so I don't see the point really.

It works well at 60fps but when it's not it breaks the game. And since this is for PC there is no way I can guarantee it will constantly run at 60 for everyone. That's why I think this is a problem.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: SetVelocity with fixed update
« Reply #7 on: June 12, 2018, 02:41:34 PM »
Hi,
It can be that there is some lag in the editor but not in a build (due to several reasons inside the editor.
But there can be many other reasons.

Maybe you can make a video or something?

You can also pm me if you do not wish to do that public.

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #8 on: June 12, 2018, 03:18:26 PM »
I think there might be some misunderstanding here.  ;D I WANT it to lag, that's when the problem occurs and I want a solution that works even when the frame rate is jumping up and down.

Maybe I could PM you some screens of my jump setup if you don't mind?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3380
    • View Profile
    • jinxtergames
Re: SetVelocity with fixed update
« Reply #9 on: June 13, 2018, 02:53:36 AM »
Hi.
Yes no problem.

Okey that's something different :)

You mean like a sort of retro style jumping?

1st think that comes in my mind is by using an array loop which would hold
a bunch of y positions to 'Animate' the jump.
and use a wait and array get next to loop thru each position.

if the floor for you game has different heights you would also need a raycast to look after each position if the floor is nearby.

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 123
    • View Profile
Re: SetVelocity with fixed update
« Reply #10 on: June 13, 2018, 08:03:02 AM »
He means that he wants to be able to replicate the lag so he can figure out how to make it run smoothly at any frame rate.

Have you tried setting the vSync count to 0 in the editor and then using the "TargetFrameRate" action to set the frame rate to something like 30?

That might do the trick.
« Last Edit: June 13, 2018, 08:06:51 AM by LordHorusNL »

Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #11 on: June 13, 2018, 09:17:04 AM »
https://youtu.be/mKbeiVwcOq8

Ok, here is a short video of the problem.

First I jump at 60fps. Then I change Time Scale to 50% and look how much shorter the jump is.

I tested target framerate to 30 and then you jumped much further instead.

How can this happen if SetVelocity really moves you per frame??

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 123
    • View Profile
Re: SetVelocity with fixed update
« Reply #12 on: June 13, 2018, 10:44:26 AM »
Why change the timescale? Timescale and physics are linked in unity and changing the timescale will thus impact the way your physics behave, at least as i understand it.

Do you get the same result when running at normal time, with vSync to 0, target framerate to let's say 30 and in full build?

I've read people have problems with target framerate in the editor.


Mupp

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: SetVelocity with fixed update
« Reply #13 on: June 13, 2018, 12:27:38 PM »
Why change the timescale? Timescale and physics are linked in unity and changing the timescale will thus impact the way your physics behave, at least as i understand it.
To see what happens. And what happens is that you jump shorter, just as if the framerate would drop.
Quote
Do you get the same result when running at normal time, with vSync to 0, target framerate to let's say 30 and in full build?
No, if you set it manually you jump further for some reason. Running in a build makes no difference.

I think I need a way to cut out the physics engine completely, but how do I move an object without it?