0
Answered

Migrating time.deltatime to timeline.deltatime

kemikalx61 2 years ago updated 2 years ago 5 1 duplicate

Greetings,

As the topic suggest, ive added chronos to my program and im working on my migration. 

In my game, I have a platform that when I stand on it for X amount of time the platform falls. Below is my previous code.


protected virtual void FixedUpdate()
{
// we send our various states to the animator.
UpdateAnimator ();      
            if (_timer < 0)
               
            {
                
            //    Timeline p = new Timeline();
              //  Timeline p = gameObject.GetComponent<Timeline>();
                //_newPosition = new Vector2(0,-FallSpeed* p.deltaTime);
                    _newPosition = new Vector2(0, -FallSpeed * Time.deltaTime);
                //  _newPosition = new Vector2(0, -FallSpeed * 0.01f);
                transform.Translate(_newPosition,Space.World);

if (transform.position.y < _bounds.min.y)
{
DisableFallingPlatform ();
}
}
}
public virtual void OnTriggerStay2D(Collider2D collider)
{
CorgiController controller=collider.GetComponent<CorgiController>();
if (controller==null)
return;

if (TimeBeforeFall>0)
{
_platformTopY = (_collider2D != null) ? _collider2D.bounds.max.y : this.transform.position.y; if (controller.ColliderBottomPosition.y >= _platformTopY)
{
                    //  Timeline p = new Timeline();
                 //    Timeline p = gameObject.GetComponent<Timeline>();
                //    _timer -= p.deltaTime;
                    _timer -= Time.deltaTime;
                    _shaking =true;
}
}
else
{
_shaking=false;
}
}


Again this is the previous code and it works just fine. Now ive followed the tutorial and added a timeline script to my platform. I've also replaced time.deltatime with the following.

                    Timeline p = gameObject.GetComponent<Timeline>();
                    _timer -= p.deltaTime;

and 

                Timeline p = gameObject.GetComponent<Timeline>();
                _newPosition = new Vector2(0,-FallSpeed* p.deltaTime);

Upon testing, I noticed that the platform didnt respect the time it was suppposed to fall in and stayed longer than it should. However pausing, rewind, fast forward worked. The second problem I noticed was when the platforrm was falling and I reversed it to it's orginal position, a few seconds later the platform begin going up. Really strange, is there something that im doing wrong with Deltatime?

Chronos Version:
Unity Version:
GOOD, I'M SATISFIED

Greatly appreciated


Satisfaction mark by kemikalx61 2 years ago

Duplicates 1

Here is another example. In  script attached to my camera, I have this code that makes my camera scroll.

I changed the code to this

void FixedUpdate () {
        Timeline p = gameObject.GetComponent<Timeline>();
 
        switch (motionState){
case motionDirections.Vertical:
                // transform.Translate (Vector3.up * scrollSpeed * Time.deltaTime);
                transform.Translate (Vector3.up * scrollSpeed * p.deltaTime);
break;
case motionDirections.Horizontal:
transform.Translate (Vector3.right * scrollSpeed * p.deltaTime);
break;
}

}

As a result, I can reverse the camera, but when the reverse is done instead of continuing back up(or right). It keeps going the wrong direction.

So example if my camera is going up, and I reverse it to go back down. It's going to keep going down down down.


Something else to note is that in my program, on the timeline after rewind the computed time begins to count in the negative where as in the example game it just stops


Answered

Hi kemikalx!

There could be many things going wrong here, it's hard to tell without the full code.

But when you say:

I noticed that the platform didnt respect the time it was suppposed to fall in and stayed longer than it should

I notice the variable TimeBeforeFall is used to determine the fall. Has this timer been ported to use Timeline.deltaTime has well?

Likewise, in scripts that update the position on Update, you should always check that the timeline isn't actively rewinding. When it is rewinding thanks to the transform recorder, you should let it do its thing and handle the transform values. If you script also tries to update the transform, there will be a conflict.

To check this, you only have to add:

if (timeline.timeScale <= 0) return;

Before your method that use timeline.deltaTime. (For example at the top of your camera script's FixedUpdate).

Hope this helps!

"I notice the variable TimeBeforeFall is used to determine the fall. Has this timer been ported to use Timeline.deltaTime has well?"

Yes, but I wish you had replied to the newer question since that one is written with more clarity.

Its just that rewinding doesnt stop updating the Y axis as it should