- Home /
Line renderer transform position problem
Hello! I have this issue, that while using line renderer, the positioning of the begin position and end position is not even near where it should be. I use the following script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProceduralLightning : MonoBehaviour {
private LineRenderer lRend;
public GameObject target;
public Vector3[] positions;
GameObject enemy;
void Start () {
lRend = GetComponent<LineRenderer> ();
}
void Update () {
RaycastHit2D seeingObject = Physics2D.Raycast(new Vector2(transform.position.x + 2, transform.position.y), Vector2.right);
if (seeingObject.collider != null) {
if (seeingObject.collider.gameObject.tag == "Enemy") {
target = seeingObject.collider.gameObject;
}
} else { target = null; }
if (target == null) {
lRend.numPositions = 0;
}
if (Input.GetKey (KeyCode.Space)) {
if (target != null) {
Vector3[] positions = new Vector3[7];
positions [0] = GameObject.FindGameObjectWithTag ("Player").gameObject.transform.position;
positions [1] = new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), 0);
positions [2] = new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), 0);
positions [3] = new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), 0);
positions [4] = new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), 0);
positions [5] = new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), 0);
positions [6] = target.transform.position;
lRend.numPositions = positions.Length;
lRend.SetPositions (positions);
}
}
}
}
so it should connet the lines between 2 objects in the scene, but instead of doing that, it offsets both ends somewhere completely offscreen.
I notice that it sort of resembles the required positions, but when moving my player, the beginning line, moves the same way, but much faster, creating this offset. I ust dont understand.
these are the begin,end positions:
capture.jpg
(26.3 kB)
Comment
Answer by Betmans · Jun 26, 2017 at 07:35 AM
I am really sorry for asking such a dumb question, but if for some odd reason anyone else is as dumb as me, just uncheck "Use World Space".