0
\$\begingroup\$

I want to be able to do this, but not go outside of the 4.4 meter limit, the radius is 4.4 meters, and it has zero gravity and no friction. I have a hard time explaining this, but imagine holding a hollow sphere with a little ball inside, when you shake it around the ball goes around the inside, I need something like that, but with zero gravity and no friction. I wasn't really sure how to do this, but I tried:

void Slide() {
if (slide) {
    for (uint32_t deviceIndex = 0; deviceIndex < vr::k_unMaxTrackedDeviceCount; deviceIndex++) {
        glm::vec3 position = devicePos[deviceIndex].xyz();
        if (sqrt(pow(position.x - 0.35, 2) + pow(position.y + 1.75, 2) + pow(position.z + 0.85, 2)) >= 4.4) {
            if (abs(position.x) > abs(position.y) && abs(position.x) > abs(position.z)) {
                if (position.x > 0) {
                    velocity.x = ((abs(velocity.y)) + (abs(velocity.z))) / 2;
                }
                else {
                    velocity.x = ((abs(velocity.y) * -1) + (abs(velocity.z) * -1)) / 2;
                }

            }
            if (abs(position.y) > abs(position.x) && abs(position.y) > abs(position.z)) {
                if (position.y > 0) {
                    velocity.y = ((abs(velocity.x)) + (abs(velocity.z))) / 2;
                }
                else {
                    velocity.y = ((abs(velocity.x) * -1) + (abs(velocity.z) * -1)) / 2;
                }

            }
            if (abs(position.z) > abs(position.x) && abs(position.z) > abs(position.y)) {
                if (position.z > 0) {
                    velocity.z = ((abs(velocity.x)) + (abs(velocity.y))) / 2;
                }
                else {
                    velocity.z = ((abs(velocity.x) * -1) + (abs(velocity.y) * -1)) / 2;
                }
            }
        }
    }
}

}

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

I think the easiest way would be to create a "reverse" sphere object. One that is hollow inside, and has colliders on the edges. If you can do that, it would surely be the fastest way.

If you want to do it programatically, it will be harder to answer since you gave no language / engine info. However, I will try:

You need to somehow check whether the inside ball touched the outside sphere. Since they are both spheres, you can do that with simple maths:

if((center_of_the_ball - center_of_the_sphere) + radius_of_the_ball > radius_of_the_sphere)

then we have a collision.

In that case you should change the direction of the ball. You could achieve that by rotating the current movement vector of the ball around the normal at the collision point. If I'm correct, you could use the vector between the center of ball and center of sphere as that.

\$\endgroup\$
2
  • \$\begingroup\$ I'm using C++ in Visual Studio \$\endgroup\$ Commented Mar 19, 2019 at 2:24
  • \$\begingroup\$ I think in that case, there shouldn't be anything you can't achieve in this environment that I have described:) Just a bit of math and you should be done \$\endgroup\$ Commented Mar 19, 2019 at 23:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.