Page 1 of 1

Back to the future hoverboard

Posted: Sat Feb 24, 2018 4:09 pm
by avithohol
Hello,

I am trying to implement hoverboard effect with the API, but my attempts failed so far:
https://youtu.be/88sTBjYXHxg

Hoverboard: Same as in the movie . Basically one rigidbody hover over various ground surface, about 50cm.

What i tried so far is to constantly apply force (or impulse) in pre-tick callback like this:

Code: Select all

//Pre-tick callback (note the true as last parameter)
mDynamicsWorld->setInternalTickCallback(this->onPrePhysicsTickCallback, static_cast<void*>(this), true);

//actual pre-tick callback function
void cPhysicsWorld::onPrePhysicsTickCallback(btDynamicsWorld *world, btScalar timeStep)
{
...
if(mHoverBoardRigidBody.isOnGround(0.5f))		//simple ray cast down, which return true if anything is hit below within 0.5f range
{
	mHoverBoardRigidBody.clearForces();		//seems to be neccessary, otherwise the force below doesn't come over gravity?
	mHoverBoardRigidBody.applyCentralForce(btVector(0,100000.0f * timeStep,0));	//apply force if we are on ground, it seems i have to apply extremly big Y+ force here
}
...
}

All I achieved is an oscillating body, constantly jump up and down:
https://youtu.be/88sTBjYXHxg

I tried to apply impulse, instead of force, but same effect.

Maybe a 6DOF spring would be able to solve this, but I have one body only.

I have run out of ideas so far, so any suggestion is welcome.

Thank you!

Re: Back to the future hoverboard

Posted: Sun Feb 25, 2018 6:16 am
by drleviathan
Here's an idea. Use a "spring action" to modify the hoverboard's velocity. Here is an implementation that might work. Some of the parameters need to be tuned to suit your needs.

Code: Select all

class HoverSpring : public btActionInterface {
    // Rather than define the spring's strength as "force per distance compressed"
    // we'll use "acceleration per distance compressed".  This makes the spring
    // behavior agnostic about the mass of the object.
public:
    btVector3 m_upDirection;
    btRigidBody* m_body;
    btScalar m_gravityMagnitude;
    btScalar m_depth = btScalar(0.0); // meters
    btScalar m_accelerationPerDepth = btScalar(1.0); // tune this, higher value makes for stronger spring
    btScalar m_dampingTimescale = btScalar(1.0); // tune this, lower value makes for faster damping

    HoverSpring() = delete;

    HoverSpring(btRigidBody* body) {
        setBody(body);
    }

    void setBody(btRigidBody* body) {
        assert(body);
        m_body = body;
        // assume body's gravity does not change and cache its length and direction
        btVector3 gravity = m_body->getGravity();
        m_gravityMagnitude = gravity.length();
        assert(m_gravityMagnitude > btScalar(0.0));
        m_upDirection = (btScalar(-1.0) / m_gravityMagnitude) * gravity;
    }

    void updateAction(btCollisionWorld* world, btScalar dt) override {
        // hover applies only when object is below its target height (e.g. m_depth is positive)
        // above target height the object has negative depth and its trajectory is ballistic
        if (m_depth < btScalar(0.0)) {
            return;
        }

        if (!m_body->isActive()) {
            m_body->activate();
        }

        // get the object's velocity, and split it into horizontal and vertical components
        btVector3 velocity = m_body->getLinearVelocity();
        btVector3 horizontalVelocity = velocity - velocity.dot(m_upDirection) * m_upDirection;
        btVector3 verticalVelocity = velocity - horizontalVelocity;

        // compute acceleration
        btScalar acceleration = m_gravityMagnitude + m_depth * m_accelerationPerDepth;

        // compute new vertical velocity
        verticalVelocity = (btScalar(1.0) - dt / m_dampingTimescale) * verticalVelocity + (acceleration * dt) * m_upDirection;

        // recombine components and update the object's velocity
        velocity = horizontalVelocity + verticalVelocity;
        m_body->setLinearVelocity(velocity);
    }
};

Re: Back to the future hoverboard

Posted: Sun Feb 25, 2018 3:04 pm
by avithohol
drleviathan wrote: Sun Feb 25, 2018 6:16 am Here's an idea. Use a "spring action" to modify the hoverboard's velocity. Here is an implementation that might work. Some of the parameters need to be tuned to suit your needs.

Thanks very much!
I get your idea. Though it's blowing the body away madly at the moment (I have different scales),
I understand now what spring behavior I have to aim for.

Thanks very much again!

Re: Back to the future hoverboard

Posted: Sun Feb 25, 2018 7:01 pm
by StabInTheDark
Just use the raycast vehicle controller with out the wheels.

Re: Back to the future hoverboard

Posted: Sun Feb 25, 2018 9:16 pm
by avithohol
StabInTheDark wrote: Sun Feb 25, 2018 7:01 pm Just use the raycast vehicle controller with out the wheels.
Didn't think about that, worth a try. Thanks!