I can't made the target point of a line renderer move

I am trying to implement a line renderer between my staff and the target. It works ok, when I move my staff the origin of the line follows it, but I can’t make move the end of the line:

Update calls Laser_Position, where the two points of the line are calculated. This is the code:

Hi Montse,

The LineRenderer draws a line between the starting point and a target. If the target remains the same and you rotate the staff, the line will still point to the target.

Hi Nina,

That’s why I sum the position of the staff to the position of the target. The moment the staff shoots, the second point is calculated:

private void ProcessRaycast(){

posicioFinal = hit.point - staff.position;

}

Then is assigned in Laser_Position(), called by Update():

private void Laser_Position()
{
     line.SetPosition(0, staff.position);
     line.SetPosition(1, posicioFinal+staff.position);
}

When the staff.position changes, it changes the point 0, but doesn’t seems to change the point 1, and posicioFinal only changes when the staff shoots.

Ok, it took me some days, but now I understand!:sweat_smile: I will try to rotate the line too, thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms