- Home /
LineRenderer to show trajectory of GameObject
I have this Ball which is thrown by clicking, dragging and releasing the mouse button on the screen, a force is applied to the ball calculating the drag length between OnMouseDown and OnMouseUp, and it's working good. Now I want to add a line showing the trajectory of the ball WHILE the player is dragging the mouse on the screen, so I used a LineRenderer, which is attached to the ball GameObject.
if (clicked)
{
aimLine.SetPosition(0, GetComponent<Rigidbody2D>().transform.position);
aimLine.SetPosition(1, new Vector3((startPosX - Input.mousePosition.x), (startPosY -
Input.mousePosition.y) ,0));
}
the origin of the LineRenderer is the ball position and the second point is the difference between the position of the mouse when clicked and the actual position of the mouse. I expected to have a line of proportional length of the drag, but this is the result... Also my game uses gravity is there a way to adjust the line shape taking in consideration the gravity effect?
I know it's probably something stupid, but I've been on this all day long and can't figure out what's wrong. Any help, for both questions, would be greatly appreciated.
Answer by Amanna · May 17, 2016 at 02:37 PM
This will help : http://wiki.unity3d.com/index.php/Trajectory_Simulation
Your answer
Follow this Question
Related Questions
LineRender: I can't seem to be able to set the start and end positions of the line 0 Answers
How do i cast mesh like a linerenderer? 0 Answers
Issue drawing lines between buttons - Lines overlap the buttons 2 Answers
Multicolored line (path of the object) 0 Answers
Problem with Line Renderer 1 Answer