How: Camera boom tied to player not affecting player motion?

denito
Posts: 4
Joined: Mon Jun 14, 2010 9:30 pm

How: Camera boom tied to player not affecting player motion?

Post by denito »

I want to put the camera on a "boom arm" consisting of an anchor point, a massive fulcrum object in the middle, and a light camera mount point on the end. The idea is that when the player jumps up, I want the camera to swing around the fulcrum so it's below the player and looking up, and then when the player falls I want the camera to swing back up while the player's side of the lever is pushed down in relation to the relatively stationary fulcrum. On the other hand if the player moves a substantial distance he should drag the fulcrum along with him.

The thing is, I want the camera to behave as if it is attached to the player, but I don't want the player's physics in turn affected by the camera arm. So I can't just connect the fulcrum directly to the player object, that's why I'm using an anchor object instead of connecting directly to the player. I'm using slider constraints with a fixed linear length to connect them. I turned collisions off on the anchor object and I'm using a special motion state to lock the anchor object's position to the player object, like this:

Code: Select all

void LockAnimator::setWorldTransform(btTransform const& worldTrans)
{
    // Ignore set, always use the target's transform without change
}

void LockAnimator::getWorldTransform(btTransform& worldTrans) const
{
    // forward the target's position as our position.
    target.getWorldTransform(worldTrans);
}
Unfortunately, the system of three bodies behaves really strangely when I do this, rotating and shaking rapidly until it all flies apart. It doesn't do that if I use a regular motion state on the anchor, so I'm thinking that the lack of feedback makes constraints not work right? I also have the problem that, when I'm not locking the anchor point, the system flies together, bounces apart, and then spins like a top, as if the arms were on a stretched spring that has been released, even though I'm taking care to ensure the starting distance between the points is exactly equal to the fixed linear distance of the slider constraint. What's up with that? I can make the spinning worse by deliberately making a discrepancy there, but I can't seem to eliminate the spin by minimizing the difference.

Is this the best way to accomplish what I'm trying to do?
denito
Posts: 4
Joined: Mon Jun 14, 2010 9:30 pm

Re: How: Camera boom tied to player not affecting player mot

Post by denito »

Since no one answered this and I was able to solve part of it on my own, I post this reply in case anyone comes across this question looking to solve a similar problem:

1. The trick is that if you want to use motion states to make something like my LockAnimator, you have to also change the body to a kinematic body.
2. SetGravity has to be done after you add the body to the world.
3. When you add the bodies to the world, there's an overload of addRigidBody that lets you specify a collision group and collision mask, so that your camera objects (especially your locked "anchor object"!) don't collide with anything in the game world.
4. Adding a constraint that is set to a different angle/length than the current positions of the objects causes it to snap back like a spring. I still can't seem to make it not act like a rubber band shooter even when I'm certain I have the constraint settings and the object positions right, so I'm not sure what I'm doing wrong and I'm disappointed no one has made any suggestions or explanations that could help me, but I've found it helps to make one of the objects much more massive than the others, so that it'll tend to stay in one spot until the oscillations die down.