• 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 /
avatar image
Question by Costinutz96 · Mar 18, 2014 at 11:01 AM · linerendererline

Drawing a direction arrow.

I am working on some kind of game, where i will need to point my swiping direction.

alt text

Here is my code for the line renderer:

 if (Input.GetButtonDown ("Fire1") && grounded  && !anti_swipe ) {
             start = Input.mousePosition;    mouseFireDown = true;
 
         } else if (Input.GetButtonUp ("Fire1") && grounded && !anti_swipe) { mouseFireDown = false;


                 if (start != Input.mousePosition && grounded) {
 
                         grounded = false;
                         timerDone = true;
                         
                         float dist = 0; 
 
                         body.AddForce ((Input.mousePosition - start) * 2.1f);
                         body.gravityScale = 1;
                         
                     anti_swipe = false;
                     lineRenderer.SetPosition(1,Vector3.zero);
 
                 }
             }
         if (mouseFireDown) {
             Debug.DrawLine (pos, Input.mousePosition - start, Color.green, 1, false);
             Vector3 pointAlongLine = Vector3.Normalize((Input.mousePosition - start) - pos + (Input.mousePosition - start));
             lineRenderer.SetPosition(1, (Input.mousePosition - start)*0.01f);
 
         }

I am trying to imitate the angry birds dotted line. I don't need trajectory prediction. Only a straight line made of dots. How can i do t$$anonymous$$s ?

Forgot to say that i am swiping in the direction i want the character to go.

alt text

PS:The scene is a demo i used to learn unity.

new bitmap image.png (69.2 kB)
new bitmap image.png (176.6 kB)
Comment
tobyfee

People who like this

1 Show 4
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 Owen-Reynolds · Mar 18, 2014 at 02:58 PM 2
Share

Very nice description of the set-up, but I think you forgot to say what your question is?

avatar image Costinutz96 · Mar 18, 2014 at 09:11 PM 0
Share

My question is: How can i imitate Angry Birds's dotted trajectory line ? Sorry for my bad english!

avatar image Owen-Reynolds · Mar 19, 2014 at 06:20 AM 0
Share

You first wrote not a trajectory, but a straight line. But then the picture and the comment are a (curved?) trajectory. A straight dotted line is easier, so it matters which one.

avatar image Costinutz96 · Mar 19, 2014 at 08:43 AM 0
Share

Just a straight line, made of dots. The more i slide, more dots the line has. Thanks!

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Owen-Reynolds · Mar 19, 2014 at 10:07 PM

For a straight line between two points, can stretch a plane between them, with a single tiled dot texture:

o Make a plane with a dot texture you made (or a small-dot, big dot texture. Whatever should repeat.)

o Find the midpoint between objects: Vector pos = (start.position+target.position)*0.5f; and put the plane there.

o Aim it at the target: dotLine.LookAt(target);. That will aim the Z at the target, with the Y aimed up. So may need to use the c$$anonymous$$ld trick so the dots go along z and Y-up has the plane facing you.

o Stretch the plane that distance: float dist=(target.position - start.position).magnitude; dotPlane.localScale = new Vector3(0.8f, 1, diet);. I just picked 0.8 as a good t$$anonymous$$ckness. If you use the default plane, it's 2 units long, so may have to use dist/2.

o Tile the dots. Just stretc$$anonymous$$ng the plane gives a really long, t$$anonymous$$n dot. You can make more dots by scaling the material. dotPlane.renderer.material.mainTextureScale = new Vector2(1, dist);. If you want, say, 2 dots/unit, use dist*2.

Comment
Lo0NuhtiK

People who like this

1 Show 0 · 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

Answer by robertbu · Mar 18, 2014 at 09:30 PM

One answer here:

http://answers.unity3d.com/questions/538199/how-to-create-a-2d-parabolic-trajectory-prediction.html

Another answer with the core calculations here:

http://answers.unity3d.com/questions/606720/drawing-projectile-trajectory.html

Comment
40detectives

People who like this

1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

LineRenderer Distortion 2 Answers

Unity Linerenderer Jaggy Lines 3 Answers

How to make dotted line for Bubble game? 1 Answer

Draw out Line in C# 0 Answers

Draw Line and detect line collision 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