#Lerping through LineRenderer Positions
1 messages · Page 1 of 1 (latest)
Q:
Where are you checking if it has reached the first Lerp destination?
A:
sliderpath++
whenever b is 1 it means it did reached
so then this goes up by 1 and futher code will be with different calculations
Explain how float b works.
its basically percent of path at which object currenty supposed to be in
Yes, the 0-1, but I want to know what game logic it is tied to
so like every variable in it
I mean explain practically, without using code language, in plain English, what is it doing?
moves object along line, when it reaches corner of line it divides its line out of itself
because else after reaching 1 it would never go back to 0
Alright, so the intent of that code is to keep track of how many points it has passed, and that part seems to be working?
most lines seem to work properly
issue appears mostly when linerenderer has many points
never when has like 2 or 3
Looking at the script, it is hard to read.
If you divide code segments into methods, you could write the main part of the script like normal language. Makes commenting less necessary, and the code easier to read.
This script is also missing comments, I'm not confident I can help you solve this as-is.
However, I think you'd be best served with creating a new script, and making the Lerping through Line Points mechanic separately, and then just copy/pasting it into the existing script, and plug in your own variables.
im pretty sure c variable is the only thing that needs adjusting
as that takes main job of turning b back from 1 to 0
i remember messing with it i could make the "broken" lines working again but non broken ones were breaking then
in those situations Github is a lifesaver
I've tracked some variables, but it's too much back and forth.
You can reduce the mental capacity required to work with this code, by rewriting it with more language related logic.
Though, I suppose you're more interested in solving this, but I really do think it is faster to make the base mechanic from scratch, make it modular, so it's proven, and then implement it.
modular wont work since i have no information about supposed length of linerenderers
Some light examples:
private Vector3 ClampedDestination(Vector3 origin, Vector3 destination, float maxDistance)
{
float distance = Vector3.Distance(destination, origin);
float clampedDistance = distance;
bool maxDistanceIsRelevant = maxDistance > 0f;
bool distanceIsHigherThanMax = distance > maxDistance;
if (maxDistanceIsRelevant && distanceIsHigherThanMax)
{
float overflow = (distance - maxDistance);
clampedDistance -= overflow;
}
Vector3 direction = (destination - origin).normalized;
Vector3 clampedDestination = origin + (direction * clampedDistance);
return clampedDestination;
}
private Vector3 Direction(Vector3 origin, Vector3 destination)
{
return (destination - origin).normalized;
}
private Vector3 MoveInDirectionForDistance(Vector3 origin, Vector3 direction, float distance)
{
return origin + (direction * distance);
}
they are assumed and they are wrong
so i wanted script auto adjust to them
float c = additionaldistance / (f * (slidertimeadd / 2));
and this seems to make broken linerenderers nearly perfectly working
but breaks regular ones
broken?
so your code only works on one side of one or more of the axes
that's the problem with this script - finding that logic in a needlessly huge haystack
Not sure what you mean by modular not working. That's just prudent coding, which works however you want it to.
based on stuff i was checking before it breaks whenever linerenderer has 2 points in same position
Debug the values and figure out what's wrong, and/or make a check for that and a solution.