playMaker

Author Topic: What's the underlying execution order of FSM and other scripts?  (Read 2356 times)

ryf9059

  • Full Member
  • ***
  • Posts: 100
I run into some problem of FSM and the script not being synced in a frame so it runs very choppy.

Here is my case:
I try to use a camera to follow a player, and a background that follows the camera and there are some scripting on the background so when the camera moves the background moves along with the camera, and with a little scripting I can achieve a parallax effect.

My approach:
Initially what I did is to use translate on the camera (the translation vector is the moving distance of the player), with fixed update selected (if not the camera will move slower than the camera and cannot follow). It works normally.

I then want to improve my method by using a camera target. And this time rather than using translate, I use get position of the camera target and then set the position on the camera itslef. It should work the same way theoratically, as I would have expect.

The results:
But the fact is that when running. The background is jumping left and right along the movement of the player.
I then investigated this issue and find out this might have something with the script I attached to the background. If I deselect the script, the background will stay still relative to the camera while the forground moves, that says, it works normally.
If I select the script and run again, the problem happens.
So I figure this has something to do with the execution order of FSM and scripts, that they have NOT been synced into the same frame.
Also, this problem happens intermitently (some case more jumpy and some case less) and the cause is unknown. It seemed totally random to me.

Any advise on why this problem will happen? Is it possibly related to the execution order os FSMs and scripts? Are they controllable?

P.S. There is an issue with my video card, it overheats itself and the game in general runs choppily, and I don't know if this has anything to do with it. Since no matter how choppy it is, the order should still be the same. It looks to be like the background script and the camera FSM is not executed in the correct order
« Last Edit: June 07, 2013, 06:23:34 AM by ryf9059 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: What's the underlying execution order of FSM and other scripts?
« Reply #1 on: June 07, 2013, 07:03:06 AM »
Hi,
 
not the likely problem you are experiencing is simply that the camer tries to catch up with a physics based gameobject.

 is that the case? if your camera needs to follow a physics based object you need to following it using "fixedUpdate" in your actions, where possible/available.

bye,

 Jean

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: What's the underlying execution order of FSM and other scripts?
« Reply #2 on: June 07, 2013, 10:56:27 AM »
not the likely problem you are experiencing is simply that the camer tries to catch up with a physics based gameobject.

 is that the case? if your camera needs to follow a physics based object you need to following it using "fixedUpdate" in your actions, where possible/available.

I'm using camera to follow the player which is controlled by axis (get axis and then translate), I have per second, every frame and fixed update enabled. The camera uses get/set position of player and the background uses get/set position of camera

EDIT: After some more debugging I think this might have something to do with the player translation.
I removed the entire background and attached the camera directly as a child of the player and disable the camera FSM, but the forground it still behaves jumpy. So this must have something to do with translation.
But I already used fixed update, every frame along with per second option. What can I do? (I didn't multiply by the deltatime in this translation, not sure how to get it)
« Last Edit: June 07, 2013, 11:27:51 AM by ryf9059 »