Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Vakinox on July 31, 2013, 10:43:40 pm

Title: Camera Moving
Post by: Vakinox on July 31, 2013, 10:43:40 pm
Have everything set up, just can't seem to get the camera to slowly move into position.
Instead it wants to jump right to the coordinates, rather than slide to them.

Code: (javascript) [Select]
 for (var i = 0; i < 24;){SetCameraY(GetCameraY()-1); while(TimeCatch + 100 > GetTime()){ ++i;}} 


To me, this reads:
1.) For as long as i = 0, then keep performing the for-loop until i is no longer less than 24 pixels
2.) As long as i is less than 24, Set the Camera -1 in pixels every 100ms
3.) While 100ms in time is added, i is added a +1.

Meaning: the Camera should move -1 on the Y-axis every 100msecs, correct?
Instead it only moves -1 once, then stops.
For all the other scripts I implemented, the camera just instantly jumps 24 pixels
Title: Re: Camera Moving
Post by: Radnen on July 31, 2013, 10:47:45 pm
If that is intended to run real-time in an update script you can't use blocking code. And you need to reset the clock like so:

Code: (javascript) [Select]

// an if causes this to merely be checked rather than wait for it to be true
if (TimeCatch + 100 < GetTime()) {
    ++i;
    TimeCatch = GetTime(); // so it can get ready for the next 100 ms.
}


Once you have that working you might want to upgrade to a tweening library which is used to move stuff around over time or some delta.
Title: Re: Camera Moving
Post by: Fat Cerberus on August 01, 2013, 09:26:05 am
Quote from: Radnen link=topic=173.msg2018#msg2018 date=
Once you have that working you might want to upgrade to a tweening library which is used to move stuff around over time or some delta.
[/quote


Scenario has a tweener built in, just putting that out there. :)