- Home /
Line Renderer Rotation is off.
Hey guys, I'm currently working on a school project that is nearly finished. This game focusses on using lightsbeams to solve puzzles. However there's one little problem. I'm using raycasts to determine if this lightsource hits a receiver, and its functioning very well. However, on the visual part, I'm using Line Renderers to visualize a beam for the player. Whenever I rotate the parent object ( 1 Sphere, with Children: ParticleSystem, Raycaster, Line Renderer) everything rotates in the right direction except for the Line Renderer. The Line Renderer rotates with some sort of anchor point which messes up the beam direction. Pics below:
http://imgur.com/O9Rtw, http://imgur.com/GWFy2, http://imgur.com/H6UwY (Raycast not included in the pictures, but the particles in these pictures matches the raycast perfectly)
I don't know what is causing this problem, but as far as I know its not the rotation. Because everytime I rotate the orb in a 90, 180, 270 or 360 degrees way, the Line Renderer is matching the raycast perfectly, except for the degrees between these 4 keypoints.
I've been searching both the scripting reference and these forums for solutions or similar problems, but I can't find anybody with a similar problem. I've been detaching the Line Renderer object off of the parent object and updating it's rotation via another script, but that won't work either (same problem).
Could anybody help me out please? :)
Below is the code I used for creating the Raycast and the Line Renderer, and which way they are supposed to point towards.
RaycastHit hit;
Vector3 forward = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, transform.forward * rayLength, raycastColor);
int layerMask = 1 << 8;
layerMask = ~layerMask;
if(Physics.Raycast(transform.position, forward, out hit, rayLength, layerMask))
{
if(lineRenderer != null)
{
lineRenderer.SetColors(c1, c2);
if(hit.collider)
{
lineRenderer.SetPosition(1, Vector3.forward * hit.distance);
} else {
lineRenderer.SetPosition(1, Vector3.forward * 5000f);
}
}
}
Your answer
Follow this Question
Related Questions
on mouseclick if raycast hit with same tag drawline. 2 Answers
Line Renderer Disappears 1 Answer
Updating line positions with reflections 1 Answer
Aim Line (Line Renderer) not showing in 2D shooter 2 Answers
Bouncing Laser Beam 1 Answer