In Portal 2, there is a concept of an "excursion funnel", a beam of light that moves physical objects in a certain direction.
Here is a link to a demonstration.
I added a simple implementation that lets me float upward against gravity (I can't give you an example I've tried as I've lost it due to the undo buffer size being too small), however I've been having a struggle generalizing it to work with any angle.
My code so far:
// on funnel collision with body:
body->SetGravityScale(0);
// on each update, for each body that is in collision:
float s = sin(this->body->GetAngle()), c = cos(this->body->GetAngle());
b2Vec2 force = {body->GetWorld()->GetGravity().x * -s * 2.f, body->GetWorld()->GetGravity().y * -c * 2.f};
for(ServerEnt* e : collidingWith) {
e->body->ApplyForceToCenter(e->body->GetMass() * force, true);
}
// on funnel end collision with body:
body->SetGravityScale(1);
This almost works, except Portal 2 funnels don't let objects fall through it, they sort of push the objects toward the center of the nearest cross-section of the funnel, which is where my code fails, or rather doesn't do anything about.
SetGravityScale
. It stops the acceleration but not the velocity, the player just goes through the tunnel. \$\endgroup\$