Forum rules - please read before posting.

Vertical reduction factor

Hi Chris, I have a quick question about how the vertical reduction factor reduces speed when the player is walking at an angle.

The reason I want to make sure I got this right is that I wrote a script where you can pick an AC path, set a start time, and the script will (1) calculate the expected time of arrival at the end of the path, and (2) manipulate the path if the player enters the scene between the start time and the expected time of arrival, so that the start of the path is placed exactly where the NPC would have been if it had started following the path at the start time. This is done and works perfectly except for one reason: so far the script doesn't take the vertical reduction factor into account when calculating the time it will take for the NPC to walk the path.

So I've just tried account for that. Does this look right to you? This is to calculate the time it takes for the NPC to walk from one node to the next.

            distance[i] = Vector3.Distance(node[i], node[i + 1]);
            angle[i] = Vector2.Angle(node[i], node[i + 1]);

            float verticalReductionFactor = AC.KickStarter.settingsManager.verticalReductionFactor;
            float verticalReductionFactorAdjusted;

            if (angle[i] > 90)
            {

                float test1 = Mathf.InverseLerp(180, 90, angle[i]);
                verticalReductionFactorAdjusted = Mathf.Lerp(verticalReductionFactor, 1, test1);

            }
            else
            {

                float test1 = Mathf.InverseLerp(0, 90, angle[i]);
                verticalReductionFactorAdjusted = Mathf.Lerp(verticalReductionFactor, 1, test1);

            }

            float realspeed = speed * verticalReductionFactorAdjusted;
            realTimeToNextNode[i] = distance[i] / realspeed;

Comments

  • Tricky one.

    You'll need to make sure that it only affects the y-axis. Personally, I'd try approaching this by splitting the distance vector, i.e:

    distance[i] = new Vector3 (distance[i].x, distance[i].y / verticalReductionFactor;
    

    My maths might be a bit off, but that should avoid the need to rely on angle-checking.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.