- Home /
Drawing a direction arrow.
I am working on some kind of game, where i will need to point my swiping direction.
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 this ?
Forgot to say that i am swiping in the direction i want the character to go.
PS:The scene is a demo i used to learn unity.
Very nice description of the set-up, but I think you forgot to say what your question is?
$$anonymous$$y question is: How can i imitate Angry Birds's dotted trajectory line ? Sorry for my bad english!
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.
Just a straight line, made of dots. The more i slide, more dots the line has. Thanks!
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 child 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 thickness. If you use the default plane, it's 2 units long, so may have to use dist/2.
o Tile the dots. Just stretching the plane gives a really long, thin 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.
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
Your answer
Follow this Question
Related Questions
Bezier curver using LineRenderer 0 Answers
How to draw a line between objects and get distance 1 Answer
LineRenderer lagging behind 1 Answer
Creating a Ray Gun 1 Answer