shmups.system11.org

Shmups Forum
 
* FAQ    * Search
 * Register  * Login 
It is currently Wed Sep 23, 2020 6:24 am View unanswered posts
View active topics



Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Mon Sep 07, 2020 12:05 pm 


User avatar

Joined: 13 Jan 2020
Posts: 22
I have some jitters in my project.
Can you help me ?

https://forum.unity.com/threads/scrolli ... st-6283940


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Tue Sep 08, 2020 7:14 pm 



Joined: 01 Mar 2008
Posts: 96
Location: Finland
The "jitters" in the video you posted in the Unity thread are scrolling artefacts caused by the low resolution scrolling.
For ultra smooth low res scrolling you need your scroll speed per pixels to be multiple of your screen refresh rate, otherwise it will always look a bit jittery.

Common trick for parallax layers is to scroll at half speed to the previous layer.

Achieving this in Unity needs just some basic math.
* Extract the pixel distance from your tile size

-> scroll speed is pixel distance * speed * frame rate

Speed should be 1/x or interger value for faster than 1 pixel per frame scrolling.
Other values will work but the outcome will always look a bit jittery


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Thu Sep 10, 2020 8:33 am 


User avatar

Joined: 13 Jan 2020
Posts: 22
Thanks a lot for your answer.
I modified my scrolling script attached to my camera like this :

Code:
public class Scrolling : MonoBehaviour
{
    public float SpeedX;
    public float SpeedY;
    public float pixelsPerUnit;
    //public bool alignHalfPixelsOff_XAxis;
    //private bool alignHalfPixelsOff_YAxis;

    public bool FixJitters; //launch a built to see the result (may still have jitters in editor)


    void Update()
    {
        transform.Translate(SpeedX * Time.deltaTime, SpeedY * Time.deltaTime, 0);

        if (FixJitters)
        {
            int i_x = Mathf.FloorToInt(transform.localPosition.x * (float)pixelsPerUnit);
            int i_y = Mathf.FloorToInt(transform.localPosition.y * (float)pixelsPerUnit);
            int i_z = Mathf.FloorToInt(transform.localPosition.z * (float)pixelsPerUnit);
            //Vector3 oldPos = transform.localPosition;
            Vector3 p = new Vector3((float)i_x / (float)pixelsPerUnit, (float)i_y / (float)pixelsPerUnit, (float)i_z / (float)pixelsPerUnit);
            //float halfSize = (1.0F / (float)pixelsPerUnit) * 0.5F;
            //if (alignHalfPixelsOff_XAxis){p.x += halfSize;}
            //if (alignHalfPixelsOff_YAxis){p.y += halfSize;}
            transform.localPosition = p;
        }
    }
}




There are no more jitters now, like you can see here :
https://twitter.com/9uileTweet/status/1303457642434658304?s=20

I don't understand why but when SpeedX is below 4, there was a lot of jitters and below 3.5 the scrolling don't move ! weird isn't it ?:)

Now, i'll have to test it in my game project to see the result.

Thank you !


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Thu Sep 10, 2020 8:40 am 



Joined: 01 Mar 2008
Posts: 96
Location: Finland
That's pretty simple.
You apply the movement as a lossy format. At low-enough speeds the sub pixel correction is stronger than the movement so the translation gets overridden by the pixel correction

You should have the scroll offset stored to a field which is independent on the pixel grid.

Then you apply the pixel-correct scroll offset as a translation.


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Sat Sep 12, 2020 10:32 am 


User avatar

Joined: 13 Jan 2020
Posts: 22
I modify my code with this :

I store the X offset like this :
scrolloffsetX = oldPos.x - p.x;

and then add this offset in this line :
transform.position = transform.position + new Vector3((SpeedX * Time.deltaTime) + scrolloffsetX, SpeedY * Time.deltaTime, 0);

Now, the scrolling occurs with SpeedX values below '4' but it wasn't fluid even with higher values than '4'.

I put a link to the demo project if you want to see (you need to built the project because results can be weird in the editor):
https://www.dropbox.com/s/fc7ma3ew5q626 ... 9.zip?dl=0

Code:
 void Update()
    {
        //transform.Translate(SpeedX * Time.deltaTime, SpeedY * Time.deltaTime, 0);
        transform.position = transform.position + new Vector3((SpeedX * Time.deltaTime) + scrolloffsetX, SpeedY * Time.deltaTime, 0);
       
        if (FixJitters)
        {
            Vector3 oldPos = transform.localPosition;

            int i_x = Mathf.FloorToInt(transform.localPosition.x * (float)pixelsPerUnit);
            int i_y = Mathf.FloorToInt(transform.localPosition.y * (float)pixelsPerUnit);
            int i_z = Mathf.FloorToInt(transform.localPosition.z * (float)pixelsPerUnit);

            Vector3 p = new Vector3((float)i_x / (float)pixelsPerUnit, (float)i_y / (float)pixelsPerUnit, (float)i_z / (float)pixelsPerUnit);
           
            //float halfSize = (1.0F / (float)pixelsPerUnit) * 0.5F;
            // if (alignHalfPixelsOff_XAxis){p.x += halfSize;}
            //if (alignHalfPixelsOff_YAxis){p.y += halfSize;}
           
            scrolloffsetX = oldPos.x - p.x;
           
            transform.localPosition = p;
        }
    }


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Sat Sep 12, 2020 12:29 pm 


User avatar

Joined: 24 Jun 2014
Posts: 444
Location: Netherlands
Did you consider to also rotate the ship/fire direction when you move x/y axis?
_________________
Visit: https://shmu.ps
Experience the National Video Game Museum in the Netherlands


Top
 Offline Profile  
 
 Post subject: Re: WIP SHMUP : Learn basics
PostPosted: Sun Sep 13, 2020 9:24 am 


User avatar

Joined: 13 Jan 2020
Posts: 22
Yes, but right now my issue is just the scrolling jitters. :)


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Space Pilot 3K template by Jakob Persson
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group