How can I lerp to position on plane based on rotation

Hey guys.

I’m basically trying to recreate those Excursion Funnels that are in Portal 2 - those blue and orange zones that you kind of ride in (check the link and you’ll know what I’m talking about!).

While in those funnels, you defy gravity and are pushed in the direction of the funnel.

In addition to this, the player also kind of lerps in TOWARDS THE CENTER of the funnel itself. So, if it is a horizontal funnel, the player’s Y and X position will always be in the center, while the funnel pushes them into the Z axis.

This is my funnel “zone” in the game.


It is a simple Trigger area with a particle system at the bottom. When I enter the zone, I switch the gravity off of the player and move his rigidbody in the direction of the zone’s transform.up. This works almost perfectly - no matter what direction this is rotated.

However, I am unable to lerp the player towards the center of the funnel. I seriously have no idea how.

In the image shown above, the player would lerp his XZ position while being pushed in the Y direction. I can hard code this, of course… but how do I make this work regardless of the rotation?

I am stumped and would love some help and feedback! Cheers!

You’d probably get it with something like, calc the ‘Nearest Point On Line’ where the Line is the center of the box
(transform.position = start, transform.up = line direction)

That gets you where it ‘should be’ at the moment, so move towards it

Vector3 NearestPointOnLine(Vector3 lineStart, Vector3 lineDir, Vector3 point){    
        //get vector from point on line to point in space
        Vector3 startToPoint = point - lineStart;
        float t = Vector3.Dot(startToPoint , lineDir);
        return lineStart + lineDir * t;
    }

@hpjohn
You’re an absolute legend! Thank you so much, it’s working exactly how I want it to! I’ll post my results very soon and show how it works.

Oh, and congrats on your 1,337th post!

EDIT: Here’s a video of what I was able to do!

Hi!
Would you mind sharing your Excursion Funnel script? How did find dots in space that form the line from entry point to the end. i managed to do it but only if I don’t rotate my object. Any help would be appreciated!