Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Ditech · May 21, 2019 at 05:09 PM · 2d gamelineinfinitelines

Help with infinite line

Hi, i am having trouble making a 2d game with 4 separate lines on which the player(dot, or cube) would move, they need to be infinite lines. i have some ideas about creating them with line renderer? not looking for a specific solution, rather a direction or advice on where to start. alt text

untitled-1111.jpg (30.8 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · May 21, 2019 at 07:23 PM 0
Share

if you can use linerenderer it is a easy way of achieving this, you will have to create a new linerenderer whenever you leave a blank space between lines, if you have any questions ask them :)

avatar image Ditech xxmariofer · May 28, 2019 at 06:14 PM 0
Share

can you help with this, how would you create 4 different line renderers that go to infinity, cross each other but never overlap and go one over each other

avatar image xxmariofer Ditech · May 28, 2019 at 08:05 PM 0
Share

yes i can help you but i need to know if the lines get cut like in your example since that ahs extra work

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · May 22, 2019 at 11:44 AM

Hello.

I dnt know if its the best solution, but if i have to do this i would do little different.

For the image, i can imagine all time the lines go in same direction (they crosss each other, but always go ahead), so i would have several lines segments as a prefab, and instantiate them continusly in front and delete then once out of scene.

This way, will have only few line objects in scene at same time, and can be instantiating new lines to the infinite.

Bye!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ditech · May 28, 2019 at 06:12 PM 0
Share

i thought of this, but then lines would have to end at the same point, meaning they would have to be evenly spaced, maybe illustration is not the best, but lines can go left and right and end at different positions, so the space between them wont always be same

avatar image
0

Answer by xxmariofer · May 28, 2019 at 08:35 PM

here is the code, try this

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Test : MonoBehaviour
 {
     private LineRenderer[] lines;
     private int currentPosition;
 
     void Awake()
     {
         currentPosition = 2;
 
         lines = new LineRenderer[4];
         for (int i = 0; i < 4; i++)
         {
             GameObject lineParent = new GameObject();
             lines[i] = lineParent.AddComponent<LineRenderer>();
 
             lines[i].startWidth = 0.5f;
             lines[i].endWidth = 0.5f;
 
             lines[i].SetPosition(0, new Vector3(i, 0, 0));
             lines[i].SetPosition(1, new Vector3(i, 0, 1));
         }
 
         StartCoroutine(NextIteration());
     }
 
     public IEnumerator NextIteration()
     {
         while(true)
         {
             yield return new WaitForSeconds(1f);
 
             if(Random.Range(0, 5) == 0)
             {
                 Shuffle();
             }
 
             for (int i = 0; i < 4; i++)
             {
                 lines[i].positionCount = currentPosition + 1;
                 lines[i].SetPosition(currentPosition, new Vector3(i, 0, currentPosition));
             }
 
             currentPosition++;
         }
     }
 
     private void Shuffle()
     {
         int index1 = Random.Range(0, 4);
         int index2;
 
         do { index2 = Random.Range(0, 4); } while (index2 == index1);
 
         LineRenderer tmp = lines[index1];
 
         lines[index1] = lines[index2];
         lines[index2] = tmp;
     }
 }
 

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ditech · May 30, 2019 at 04:08 PM 0
Share

no sorry, not even close. i want lines to be going independently one from another, to go left and right and to cut other lines totally random. i am not looking for a solution written in code, rather an idea how to get to that point. the main problem is how to detect if a new generated position of a line, will be at other line.

avatar image xxmariofer Ditech · May 30, 2019 at 07:02 PM 0
Share

You need to br more specific since the code i provided is totally random, they cut each other and they go left and right, unless you tell us what the exact diference of my solution and what you want to achieve we cant help you, with the codr i provided yoy can difectly have that same drawn as yours

avatar image
0

Answer by Ditech · May 30, 2019 at 07:33 PM

so far i have managed to create 4 lines, randomly generated to always stay within the borders of the screen. but can't quite figure how to stop them going one over another... here is screenshot maybe it will help explain better what is happening.alt text


screen-shot-2019-05-30-at-212915.png (31.0 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

201 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create an Animated 2D Line to help the user aim and shoot? 1 Answer

Unity Linerenderer jaggy lines 0 Answers

How to remove lines occurring between images in 6-sided skyboxes 0 Answers

Infinite Scrollview and Read A File Line By Line 0 Answers

How to remove the "lines" that appear sometimes when previewing the game? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges