Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    3

    2D Shooter; scrolling background issues...

    Hey guys I'm working through the 2D space shooter tutorial and it is pretty straight forward up until now.

    I'm a bit stuck on the scrolling background portion. It works for the most part, but small gaps and overlaps tend to randomly occur.

    In the code, I've modified it a bit because I want my geo to scroll from left to right instead of how they had it. Everything works except for the fact that things don't bump up precisely behind each other like they should every single time.

    I'm wondering if the culprit is Time.deltaTime and that maybe I should be using something better...but I don't know what? If you look closely in the video here on 3D Buzz...they have the same issue in the scene view although you don't notice it because the overlap is black.

    I apologize in advance as I am a stupid artist just trying to get his feet wet here. Thanks to anyone checking this out.

    Code:
    using UnityEngine;
    using System.Collections;
    
    public class ground01 : MonoBehaviour
    {
    	#region Fields
    	public int Speed;
    	#endregion
    	
    	#region Functions
    	void Start()
    	{
    		
    	}
    	
    	void Update()
    	{
    		float amtToMove = Speed * Time.deltaTime;
    		transform.Translate(Vector3.right * amtToMove, Space.World);
    		
    		if (transform.position.x > 25)
    		{
    			transform.position = new Vector3(-25f, transform.position.y, transform.position.z);
    		}
    	}
    	#endregion
    }
    Last edited by Junkie_XL; 04-07-2012 at 07:23 PM.

  2. #2
    Join Date
    Jun 2003
    Posts
    150
    I don't see anything particularly wrong with the code. Time.deltatime certainly isn't the problem. It sounds more like there's an initial position problem in the editor with the two planes. To be honest I found the cylinder method mentioned in the videos easier to implement as all it did was tell a cylinder to use transform.Rotate() every frame. Didn't have to check to see if something needed to be repositioned at all.

  3. #3
    Join Date
    Dec 2008
    Posts
    3
    okay so removing Time.deltaTime makes it snap back precisely forever...just had to tone the speed way down. But now it feels a bit more jittery than before. I guess without Time.deltaTime things aren't updating properly with the framerate or something?

    The reason why I'm not going with the cylinder or scrolling UV's is because I eventually want to replace these ground planes with chunks of geo that are more elaborate. I'm doing more side scrolling 3D with the planes at an angle going off into the distance.

    I'm beginning to think I may have an easier time animating this with Unity's curve editor or in 3ds max. Not sure if the jitter will still be a problem or not.
    Last edited by Junkie_XL; 04-08-2012 at 12:39 AM.

  4. #4
    Join Date
    Jun 2003
    Posts
    150
    Without deltaTime the movement speed will not be consistent between machines as the speed will run as fast as the processor allows at the time, which fluctuates based on processing load and maximum speed of the computer.

    Another thing to keep in mind is they were doing things a in very quick and dirty way, changing things like the size of the screen and setting absolute values to move to will cause undesired effects. The video series was more about getting people who were familiar with programming in general but have never worked with Unity's workflow as the video has many many horrid practices.

  5. #5
    Join Date
    Dec 2008
    Posts
    3
    Quote Originally Posted by Edge Damodred View Post
    Without deltaTime the movement speed will not be consistent between machines as the speed will run as fast as the processor allows at the time, which fluctuates based on processing load and maximum speed of the computer.

    Another thing to keep in mind is they were doing things a in very quick and dirty way, changing things like the size of the screen and setting absolute values to move to will cause undesired effects. The video series was more about getting people who were familiar with programming in general but have never worked with Unity's workflow as the video has many many horrid practices.
    Fair enough and understandable. So is there something other than Time.deltaTime that I should use for this particular problem? I want consistency but gaps make baby jesus cry.

  6. #6
    Join Date
    Jun 2003
    Posts
    150
    Most likely it's an initial positioning issue of the moving planes in the editor as the code itself is fine. Try just doing it with one plane and see if that moves back to the correct spot. Then parent the second plane to that plane and make sure there's no gap between them.

    It might help if you could upload what your game looks like by uploading it as a web application somewhere.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •